Giter Club home page Giter Club logo

encode-decode's Introduction

encode / decode

library link
jackson https://github.com/FasterXML/jackson
protobuf https://developers.google.com/protocol-buffers
Thirft https://thrift.apache.org/
Avro https://github.com/prayagupa/avro-in-makwanpur
circe https://circe.github.io/circe/
argonaut https://github.com/argonaut-io/argonaut
play.json lib https://www.playframework.com/documentation/2.6.x/ScalaJson
json4s https://github.com/json4s/json4s
// find ~/.m2/repository/ -name "*.jar" | tr '\n' ':'

jshell --class-path $(find ~/.m2/repository/com/fasterxml/ -name "*.jar" | tr '\n' ':') --enable-preview
|  Welcome to JShell -- Version 12.0.1
|  For an introduction type: /help intro

jshell> import com.fasterxml.jackson.databind.ObjectMapper

jshell> var om = new ObjectMapper()
om ==> com.fasterxml.jackson.databind.ObjectMapper@30a3107a

jshell> import com.fasterxml.jackson.core.*
jshell> var json = om.readTree("{\"config\": [{ \"name\": \"a\"}, {\"name\": \"b\"}] }")
json ==> {"config":[{"name":"a"},{"name":"b"}]}

jshell> import com.fasterxml.jackson.core.JsonPointer
jshell> json.at("/config")
$12 ==> [{"name":"a"},{"name":"b"}]

jshell> json.at("/config").forEach(v -> System.out.println(v))
{"name":"a"}
{"name":"b"}
scala> val json = om.readTree("""{"config": [{ "name": "a"}, {"name": "b"}, {"name": ""}] }""")
json: com.fasterxml.jackson.databind.JsonNode = {"config":[{"name":"a"},{"name":"b"},{"name":""}]}

scala> json.at("/config").forEach(a => println(a.at("/name").textValue.nonEmpty))
true
true
false

proto

brew install protobuf
brew upgrade protobuf

protoc src/main/resources/sku.proto --java_out=src/main/java/data/

Note

encode-decode's People

Contributors

prayagupa avatar

Watchers

 avatar  avatar  avatar

encode-decode's Issues

play json serialisers

Play Serialisers

scala> import play.api.libs.json.Json._
import play.api.libs.json.Json._

scala> import play.api.libs.json._
import play.api.libs.json._

scala> final case class Android(name: String, version: String)
defined class Android

scala> final case class AiResponse[T](body: T)
defined class AiResponse

scala> implicit val androidFormat: Format[Android] = Json.format[Android]
androidFormat: play.api.libs.json.Format[Android] = play.api.libs.json.OFormat$$anon$1@2cb66c68

scala> val androidAiResponseFormat = Json.format[AiResponse[Android]]
androidAiResponseFormat: play.api.libs.json.OFormat[AiResponse[Android]] = play.api.libs.json.OFormat$$anon$1@704adf36

Serialisation

scala> Json.toJson(AiResponse(body = Android(name = "android", version = "1.0")))
res1: play.api.libs.json.JsValue = {"body":{"name":"android","version":"1.0"}}

Deserialisation

scala> Json.fromJson[AiResponse[Android]](Json.parse("""{"body":{"name":"android","version":"1.0"}}"""))
res3: play.api.libs.json.JsResult[AiResponse[Android]] = JsSuccess(AiResponse(Android(android,1.0)),)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.