All Projects → scalapb-json → scalapb-circe

scalapb-json / scalapb-circe

Licence: MIT license
Json/Protobuf convertors for ScalaPB use circe

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to scalapb-circe

akka-http-scalapb
akka-http protobuf binary and json marshalling/unmarshalling for ScalaPB messages
Stars: ✭ 15 (-60.53%)
Mutual labels:  protobuf, scalapb
kafka-serde-scala
Implicitly converts typeclass encoders to kafka Serializer, Deserializer, Serde.
Stars: ✭ 52 (+36.84%)
Mutual labels:  scalapb, circe
scalapb-playjson
Json/Protobuf convertors for ScalaPB use play-json
Stars: ✭ 15 (-60.53%)
Mutual labels:  protobuf, scalapb
rpc-spring-boot-starter
自定义rpc框架,支持Java序列化和protobuf序列化协议,多种负载均衡算法
Stars: ✭ 75 (+97.37%)
Mutual labels:  protobuf
luban
你的最佳游戏配置解决方案 {excel, csv, xls, xlsx, json, bson, xml, yaml, lua, unity scriptableobject} => {json, bson, xml, lua, yaml, protobuf(pb), msgpack, flatbuffers, erlang, custom template} data + {c++, java, c#, go(golang), lua, javascript(js), typescript(ts), erlang, rust, gdscript, protobuf schema, flatbuffers schema, custom template} code。
Stars: ✭ 1,660 (+4268.42%)
Mutual labels:  protobuf
pronto
Clojure support for protocol buffers
Stars: ✭ 66 (+73.68%)
Mutual labels:  protobuf
elm-protobuf
protobuf plugin for elm
Stars: ✭ 93 (+144.74%)
Mutual labels:  protobuf
python-riemann-client
A Riemann client and command line tool
Stars: ✭ 38 (+0%)
Mutual labels:  protobuf
fmutils
Golang protobuf FieldMask missing utils
Stars: ✭ 64 (+68.42%)
Mutual labels:  protobuf
mine.js
🌏 A voxel engine built with JS/TS/RS. (formerly mc.js) (maybe mine.ts? or even mine.rs?)
Stars: ✭ 282 (+642.11%)
Mutual labels:  protobuf
protobuf-smalltalk
Protocol buffers support for Smalltalk
Stars: ✭ 14 (-63.16%)
Mutual labels:  protobuf
mongo-db-go-protobuf-tutorial
Source code for "New official MongoDB Go Driver and Google Protobuf - making them work together" article
Stars: ✭ 18 (-52.63%)
Mutual labels:  protobuf
protobuf-decoder
JavaScript-based web UI to decode ad-hoc Protobuf data
Stars: ✭ 107 (+181.58%)
Mutual labels:  protobuf
tinyrpc
Much fast, lightweight, async, based boost.beast and protobuf.
Stars: ✭ 32 (-15.79%)
Mutual labels:  protobuf
methanol
⚗️ Lightweight HTTP extensions for Java
Stars: ✭ 172 (+352.63%)
Mutual labels:  protobuf
erda-infra
Erda Infra is a lightweight microservices framework implements by golang, which offers many useful modules and tools to help you quickly build a module-driven application
Stars: ✭ 152 (+300%)
Mutual labels:  protobuf
caffemodel2json
A small tool to dump Caffe's *.caffemodel to JSON for inspection
Stars: ✭ 40 (+5.26%)
Mutual labels:  protobuf
fs2-data
streaming data parsing and transformation library
Stars: ✭ 103 (+171.05%)
Mutual labels:  circe
apache-flink-jdbc-streaming
Sample project for Apache Flink with Streaming Engine and JDBC Sink
Stars: ✭ 22 (-42.11%)
Mutual labels:  protobuf
facebook4s
An asynchronous non-blocking Scala client for Facebook Graph API (Facebook api REST)
Stars: ✭ 18 (-52.63%)
Mutual labels:  circe

scalapb-circe

scaladoc The structure of this project is hugely inspired by scalapb-json4s

Dependency

Include in your build.sbt file

core

libraryDependencies += "io.github.scalapb-json" %% "scalapb-circe" % "0.12.1"

for scala-js or scala-native

libraryDependencies += "io.github.scalapb-json" %%% "scalapb-circe" % "0.12.1"

macros

libraryDependencies += "io.github.scalapb-json" %% "scalapb-circe-macros" % "0.12.1"

Usage

JsonFormat

There are four functions you can use directly to serialize/deserialize your messages:

JsonFormat.toJsonString(msg) // returns String
JsonFormat.toJson(msg) // returns Json

JsonFormat.fromJsonString(str) // return MessageType
JsonFormat.fromJson(json) // return MessageType

Implicit Circe Codecs

You can also import codecs to support Circe's implicit syntax for objects of type GeneratedMessage and GeneratedEnum.

Assume a proto message:

message Guitar {
  int32 number_of_strings = 1;
}
import io.circe.syntax._
import io.circe.parser._
import scalapb_circe.codec._

Guitar(42).asJson.noSpaces // returns {"numberOfStrings":42}

decode[Guitar]("""{"numberOfStrings": 42}""") // returns Right(Guitar(42))
Json.obj("numberOfStrings" -> Json.fromInt(42)).as[Guitar] // returns Right(Guitar(42))

You can define an implicit scalapb_circe.Printer and/or scalapb_circe.Parser to control printing and parsing settings. For example, to include default values in Json:

import io.circe.syntax._
import io.circe.parser._
import scalapb_circe.codec._
import scalapb_circe.Printer

implicit val p: Printer = new Printer(includingDefaultValueFields = true)

Guitar(0).asJson.noSpaces // returns {"numberOfStrings": 0}

Finally, you can include scalapb GeneratedMessage and GeneratedEnums in regular case classes with semi-auto derivation:

import io.circe.generic.semiauto._
import io.circe.syntax._
import io.circe._
import scalapb_circe.codec._ // IntelliJ might say this is unused.

case class Band(guitars: Seq[Guitar])
object Band {
  implicit val dec: Decoder[Band] = deriveDecoder[Band]
  implicit val enc: Encoder[Band] = deriveEncoder[Band]
}
Band(Seq(Guitar(42))).asJson.noSpaces // returns {"guitars":[{"numberOfStrings":42}]}

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].