SlideShare ist ein Scribd-Unternehmen logo
1 von 64
Downloaden Sie, um offline zu lesen
sbt,
history of JSON libraries,
microservices, and
schema evolution
Eugene Yokota (@eed3si9n)

February, 2017
• Scala hobbyist since 2010
• scalaxb (XML data binding)
• treehugger.scala
• sbt-assembly, sbt-buildinfo, etc
• “learning Scalaz” / “herding Cats”
• ScalaMatsuri
• Lightbend/Typesafe since 2014
• tech lead of Reactive Platform team
• current maintainer / tech lead of sbt
who is this guy (@eed3si9n)?
Lightbend Production Suite
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
big picture: development at scale
• How do you scale a technological organization?
• Goal: Sustainable development
development at scale
• Bezos mandate (written circa 2002 before AWS) https://plus.google.com/
+RipRowan/posts/eVeouesvaVX
microservice is a social stack
1. All teams will henceforth expose their data and functionality through service interfaces.
2. Teams must communicate with each other through these interfaces.
3. There will be no other form of inter-process communication allowed: no direct linking, no direct
reads of another team’s data store, no shared-memory model, no back-doors whatsoever. The only
communication allowed is via service interface calls over the network.
4. It doesn’t matter what technology they use. HTTP, Corba, Pubsub, custom protocols -- doesn't
matter. Bezos doesn't care.
5. All service interfaces, without exception, must be designed from the ground up to be externalizable.
That is to say, the team must plan and design to be able to expose the interface to developers in the
outside world. No exceptions.
6. Anyone who doesn't do this will be fired.
Brief history of
JSON libraries
Eugene Yokota (@eed3si9n)

2016
Brief history of JSON libraries
Dispatch JSON
literaljson
Lift JSON
sjson
Spray JSON
Play JSON
Argonaut
json4s
Circe
Jawn
SLIP-28 JSON
Rapture JSON
sjson-new
2009 2010 2014
2008
Two books
Programming in Scala
import scala.util.parsing.combinator._
class JSON extends JavaTokenParsers {
def value : Parser[Any] = obj | arr |
stringLiteral |
floatingPointNumber |
"null" | "true" | "false"
def obj : Parser[Any] = "{"~repsep(member, ",")~"}"
def arr : Parser[Any] = "["~repsep(value, ",")~"]"
def member: Parser[Any] = stringLiteral~":"~value
}
https://www.artima.com/pins1ed/combinator-parsing.html#31.4
• Chapter 5. Writing a library: working with JSON data
Real World Haskell
data JValue = JString String
| JNumber Double
| JBool Bool
| JNull
| JObject [(String, JValue)]
| JArray [JValue]
deriving (Eq, Ord, Show)
2009
• https://github.com/dispatch/dispatch/commit/
41edb939baa5c6edb4378c1bd8e1d2f10f3350f2
• Contributed by Jorge Ortiz
• Parsing using parser combinator
• Values stored in AST, JsValue
Dispatch JSON
• https://github.com/jonifreeman/literaljson
• Authored by Joni Freeman
• Custom parser
• Values stored in AST, JValue
• On August 11, 2009, Joni contributed literaljson to
Lift, and became Lift-JSON
jonifreeman/literaljson
2010
• https://github.com/debasishg/sjson
• Authored by Debasish Ghosh
• sjson: Now offers Type Class based JSON
Serialization in Scala
• Uses Dispatch JSON for AST
sjson
Typeclass
• Allows adding capability to a class after the fact in a
typesafe manner.
Typeclass
trait Eq[A] {
  def equals(x: A, y: A): Boolean
}
• Eq typeclass can enable === operator to compare
only the supported types, and prevent compilation
of "1" === 1
• Scala Implicits : Type Classes Here I Come
JsonFormat
trait CanRead[A] {
  def reads(json: JsValue): A
}
trait CanWrite[A] {
  def writes(a: A): JsValue
}
trait JsonFormat[A] extends CanRead[A]
with CanWrite[A]
implicit val intFormat: JsonFormat[Int] = ...
JsonFormat
• JsonFormat typeclass allows conversion to and
from an arbitrary type to a JSON AST.
2011
• https://github.com/spray/spray-json
• Authored by Mathias Dönitz
• Original parser
• Ported AST from Dispatch JSON and type classes
from sjson
spray-json
• https://github.com/playframework/playframework/commit/
63448578b15dcc7bf4806878c7b3aa4c74193af6
• Started out as port of Dispatch JSON and sjson typeclasses, but quickly
added its own implementations.
Play JSON
2012
• http://argonaut.io/
• Purely functional JSON library
• Authored by Mark Hibberd, Tony Morris, Sean Parsons
• Uses Scalaz or Cats
• Very feature rich (Lenses, Cursor, History Cursor)
Argonaut
2013
• https://github.com/json4s/json4s
• Fork of Lift-json. JSON library that is not strongly tied to a web
framework.
json4s
2014
• https://github.com/non/jawn
• Authored by Erik Osheim (@d6)
• Backend-independent JSON parser
Jawn
• http://rapture.io/mod/json
• Authored by Jon Pretty
• Backend-independent JSON library
Rapture JSON
2015
• https://github.com/travisbrown/circe
• Authored by Travis Brown
• Port of Argonaut
Circe
2016
• https://github.com/mdedetrich/scala-json-ast
• Authored by Matthew de Detrich
• Aiming to be the common JSON AST
Scala JSON AST (SLIP-28)
• https://github.com/eed3si9n/sjson-new
• Backend-independent typeclass based JSON codec
• No macros
sjson-new
Brief history of JSON libraries
Dispatch JSON
literaljson
Lift JSON
sjson
Spray JSON
Play JSON
Argonaut
json4s
Circe
Jawn
SLIP-28 JSON
Rapture JSON
sjson-new
2009 2010 2014
Contract-first approach
Eugene Yokota (@eed3si9n)

2016
• “Serialization” tends to start from a programming language construct, and it
generates String or byte array.
• Data binding starts with a contract or a schema of the wire format, and generates
the binding in a programming language.
• XML Schema / WSDL
• Google Protocol Buffer
• Apache Thrift
• Apache Avro
• Facebook GraphQL
Serialization vs Data binding
• sealed traits
• case classes
Representing data in Scala
• sealed traits
• case classes
Representing data in Scala
Cannot evolve in a binary compatible way.
Representing data in Scala
class Greeting(name: String) {
  def copy(name: String = name): Greeting = ???
  def unapply(v: Greeting): Option[String] = ???
}
class Greeting(name: String, x: Int) {
  def copy(name: String = name,
x: Int = x): Greeting = ???
  def unapply(v: Greeting): Option[(String, Int)] =
???
}
• sealed traits
• case classes
• Cannot evolve in a binary compatible way.
• But generating equals, hash, and toString is generally useful.
Representing data in Scala
Contraband
• http://www.scala-sbt.org/contraband/
• Contraband is a description language for your datatypes and APIs, currently
targeting Java and Scala.
• Based on GraphQL schema.
Contraband
Record types
package com.example
@target(Scala)
## Character represents the characters in Star Wars.
type Character {
name: String!
appearsIn: [com.example.Episode]!
}
@since annotation
package com.example
@target(Scala)
type Greeting {
value: String!
x: Int @since("0.2.0")
}
Enumeration types
package com.example
@target(Scala)
## Star Wars trilogy.
enum Episode {
NewHope
Empire
Jedi
}
Interfaces
package com.example
@target(Scala)
## Character represents the characters in Star Wars.
interface Character {
name: String!
appearsIn: [com.example.Episode]!
friends: lazy [com.example.Character]
}
Record type example
package com.example
@target(Scala)
type Person {
name: String!
age: Int
}
Record type example
// DO NOT EDIT MANUALLY
package com.example
final class Person private (
  val name: String,
  val age: Option[Int]) extends Serializable {
  override def equals(o: Any): Boolean = o match {
    case x: Person => (this.name == x.name) && (this.age ==
x.age)
    case _ => false
  }
  override def hashCode: Int = {
    37 * (37 * (17 + name.##) + age.##)
  }
  override def toString: String = {
Record type example
  override def toString: String = {
    "Person(" + name + ", " + age + ")"
  }
  protected[this] def copy(name: String = name,
age: Option[Int] = age): Person = {
    new Person(name, age)
  }
  def withName(name: String): Person = {
    copy(name = name)
  }
  def withAge(age: Option[Int]): Person = {
    copy(age = age)
  }
  def withAge(age: Int): Person = {
Record type example
object Person {
  def apply(name: String, age: Option[Int]): Person =
new Person(name, age)
  def apply(name: String, age: Int): Person =
new Person(name, Option(age))
}
Record type example
> val x = Person("Alice", 20)
> x.withAge(21)
Contraband can derive sjson-new codecs
JSON codec generation
package com.example
@target(Scala)
type Person {
name: String!
age: Int
}
JSON codec generation
package generated
import _root_.sjsonnew.{ deserializationError,
serializationError, Builder, JsonFormat, Unbuilder }
trait PersonFormats { self: sjsonnew.BasicJsonProtocol =>
  implicit lazy val personFormat: JsonFormat[_root_.Person] =
JsonFormat[_root_.Person] {
    override def read[J](jsOpt: Option[J], unbuilder:
Unbuilder[J]): _root_.Person = {
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val name = unbuilder.readField[String]("name")
          val age = unbuilder.readField[Option[Int]]("age")
          unbuilder.endObject()
          _root_.Person(name)
JSON codec generation
scala> import sjsonnew.support.scalajson.unsafe.{ Converter,
CompactPrinter, Parser }
scala> import com.example.codec.CustomJsonProtocol._
scala> import com.example.Person
scala> val p = Person("Bob", 20)
p: com.example.Person = Person(Bob, 20)
scala> val j = Converter.toJsonUnsafe(p)
j: scala.json.ast.unsafe.JValue =
JObject([Lscala.json.ast.unsafe.JField;@6731ad72)
scala> val s = CompactPrinter(j)
s: String = {"name":"Bob","age":20}
scala> val x = Parser.parseUnsafe(s)
JSON codec generation
scala> val s = CompactPrinter(j)
s: String = {"name":"Bob","age":20}
scala> val x = Parser.parseUnsafe(s)
x: scala.json.ast.unsafe.JValue =
JObject([Lscala.json.ast.unsafe.JField;@7331f7f8)
scala> val q = Converter.fromJsonUnsafe[Person](x)
q: com.example.Person = Person(Bob, 20)
scala> assert(p == q)
• http://www.scala-sbt.org/contraband/
• Contraband is a description language for your datatypes and APIs, currently
targeting Java and Scala.
• Low-tech metaprogramming (code generation)
• Binary compatible evolution of pseudo case class.
• Auto derivation of backend-independent JSON codec.
Contraband
• An opportunity for datatype-generic programming.
• For example, one backend is Int
Contraband
• An opportunity for datatype-generic programming.
• For example, one backend is Int (Murmurhash support)
• Builder API is used to build one-way hash.
Contraband
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)

Weitere ähnliche Inhalte

Was ist angesagt?

FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingRami Sayar
 
Microservices in Scala: Play Framework
Microservices in Scala: Play FrameworkMicroservices in Scala: Play Framework
Microservices in Scala: Play FrameworkŁukasz Sowa
 
Databases which, why and usage tips
Databases which, why and usage tipsDatabases which, why and usage tips
Databases which, why and usage tipsavnerner
 
Scala io2013 : Our journey from UML/MDD to Scala macros
Scala io2013 : Our journey from UML/MDD to Scala macrosScala io2013 : Our journey from UML/MDD to Scala macros
Scala io2013 : Our journey from UML/MDD to Scala macrosebiznext
 
Apache Camel in the belly of the Docker whale
Apache Camel in the belly of the Docker whaleApache Camel in the belly of the Docker whale
Apache Camel in the belly of the Docker whaleHenryk Konsek
 
JCR - Java Content Repositories
JCR - Java Content RepositoriesJCR - Java Content Repositories
JCR - Java Content RepositoriesCarsten Ziegeler
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threadsmperham
 
Java, Ruby & Rails
Java, Ruby & RailsJava, Ruby & Rails
Java, Ruby & RailsPeter Lind
 
Odnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureOdnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureDmitry Buzdin
 
Railsチュートリアルの歩き方 (第3版)
Railsチュートリアルの歩き方 (第3版)Railsチュートリアルの歩き方 (第3版)
Railsチュートリアルの歩き方 (第3版)Yohei Yasukawa
 
Spring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trendsSpring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trendsArawn Park
 
Ruby - a tester's best friend
Ruby - a tester's best friendRuby - a tester's best friend
Ruby - a tester's best friendPeter Lind
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingAlex Derkach
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js PlatformNaresh Chintalcheru
 
Ruby on rails toolbox
Ruby on rails toolboxRuby on rails toolbox
Ruby on rails toolboxBlazing Cloud
 
Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introductionSergii Fesenko
 
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Java 8: Nashorn & avatar.js di Enrico Risa al JUG RomaJava 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Java 8: Nashorn & avatar.js di Enrico Risa al JUG RomaVitalij Zadneprovskij
 

Was ist angesagt? (20)

FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript Debugging
 
Microservices in Scala: Play Framework
Microservices in Scala: Play FrameworkMicroservices in Scala: Play Framework
Microservices in Scala: Play Framework
 
Databases which, why and usage tips
Databases which, why and usage tipsDatabases which, why and usage tips
Databases which, why and usage tips
 
Perl6 meets JVM
Perl6 meets JVMPerl6 meets JVM
Perl6 meets JVM
 
Scala io2013 : Our journey from UML/MDD to Scala macros
Scala io2013 : Our journey from UML/MDD to Scala macrosScala io2013 : Our journey from UML/MDD to Scala macros
Scala io2013 : Our journey from UML/MDD to Scala macros
 
Apache Camel in the belly of the Docker whale
Apache Camel in the belly of the Docker whaleApache Camel in the belly of the Docker whale
Apache Camel in the belly of the Docker whale
 
JCR - Java Content Repositories
JCR - Java Content RepositoriesJCR - Java Content Repositories
JCR - Java Content Repositories
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Java, Ruby & Rails
Java, Ruby & RailsJava, Ruby & Rails
Java, Ruby & Rails
 
Odnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureOdnoklassniki.ru Architecture
Odnoklassniki.ru Architecture
 
Railsチュートリアルの歩き方 (第3版)
Railsチュートリアルの歩き方 (第3版)Railsチュートリアルの歩き方 (第3版)
Railsチュートリアルの歩き方 (第3版)
 
Spring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trendsSpring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trends
 
Introduction to CQ5
Introduction to CQ5Introduction to CQ5
Introduction to CQ5
 
Ruby - a tester's best friend
Ruby - a tester's best friendRuby - a tester's best friend
Ruby - a tester's best friend
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data binding
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js Platform
 
Ruby on rails toolbox
Ruby on rails toolboxRuby on rails toolbox
Ruby on rails toolbox
 
Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introduction
 
Ansible
AnsibleAnsible
Ansible
 
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Java 8: Nashorn & avatar.js di Enrico Risa al JUG RomaJava 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
 

Andere mochten auch

The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)Eugene Yokota
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The BasicsJeff Fox
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the bookCyrille Martraire
 
データベース設計徹底指南
データベース設計徹底指南データベース設計徹底指南
データベース設計徹底指南Mikiya Okuno
 
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQLHTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQLUlf Wendel
 
Taking the friction out of microservice frameworks with Lagom
Taking the friction out of microservice frameworks with LagomTaking the friction out of microservice frameworks with Lagom
Taking the friction out of microservice frameworks with LagomMarkus Eisele
 
JSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked DataJSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked DataGregg Kellogg
 
[Ecの会社でaiのラボを作りました]ネクストエンジンaiラボ
[Ecの会社でaiのラボを作りました]ネクストエンジンaiラボ[Ecの会社でaiのラボを作りました]ネクストエンジンaiラボ
[Ecの会社でaiのラボを作りました]ネクストエンジンaiラボHamee株式会社
 
冬のLock free祭り safe
冬のLock free祭り safe冬のLock free祭り safe
冬のLock free祭り safeKumazaki Hiroki
 
1.3.18 Организация ввода и распределения электроэнергии до 1 кВ
1.3.18 Организация ввода и распределения электроэнергии до 1 кВ1.3.18 Организация ввода и распределения электроэнергии до 1 кВ
1.3.18 Организация ввода и распределения электроэнергии до 1 кВIgor Golovin
 
Los 7 Principios del Cerebro
Los 7 Principios del CerebroLos 7 Principios del Cerebro
Los 7 Principios del CerebroMiguel Angel
 
Microservice.net by sergey seletsky
Microservice.net by sergey seletskyMicroservice.net by sergey seletsky
Microservice.net by sergey seletskySergey Seletsky
 
10 RAZONES PARA SALIR CON UN JUGADOR DE GOLF
10 RAZONES PARA SALIR CON UN JUGADOR DE GOLF10 RAZONES PARA SALIR CON UN JUGADOR DE GOLF
10 RAZONES PARA SALIR CON UN JUGADOR DE GOLFMassimo Filippa
 
Company presentation ppt
Company presentation pptCompany presentation ppt
Company presentation pptJock LI
 

Andere mochten auch (20)

The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the book
 
データベース設計徹底指南
データベース設計徹底指南データベース設計徹底指南
データベース設計徹底指南
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQLHTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
 
Json
JsonJson
Json
 
Taking the friction out of microservice frameworks with Lagom
Taking the friction out of microservice frameworks with LagomTaking the friction out of microservice frameworks with Lagom
Taking the friction out of microservice frameworks with Lagom
 
JSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked DataJSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked Data
 
[Ecの会社でaiのラボを作りました]ネクストエンジンaiラボ
[Ecの会社でaiのラボを作りました]ネクストエンジンaiラボ[Ecの会社でaiのラボを作りました]ネクストエンジンaiラボ
[Ecの会社でaiのラボを作りました]ネクストエンジンaiラボ
 
冬のLock free祭り safe
冬のLock free祭り safe冬のLock free祭り safe
冬のLock free祭り safe
 
1.3.18 Организация ввода и распределения электроэнергии до 1 кВ
1.3.18 Организация ввода и распределения электроэнергии до 1 кВ1.3.18 Организация ввода и распределения электроэнергии до 1 кВ
1.3.18 Организация ввода и распределения электроэнергии до 1 кВ
 
2016 in review
2016 in review2016 in review
2016 in review
 
Los 7 Principios del Cerebro
Los 7 Principios del CerebroLos 7 Principios del Cerebro
Los 7 Principios del Cerebro
 
Microservice.net by sergey seletsky
Microservice.net by sergey seletskyMicroservice.net by sergey seletsky
Microservice.net by sergey seletsky
 
10 RAZONES PARA SALIR CON UN JUGADOR DE GOLF
10 RAZONES PARA SALIR CON UN JUGADOR DE GOLF10 RAZONES PARA SALIR CON UN JUGADOR DE GOLF
10 RAZONES PARA SALIR CON UN JUGADOR DE GOLF
 
Sacred Riots
Sacred RiotsSacred Riots
Sacred Riots
 
BARRERAS
BARRERAS BARRERAS
BARRERAS
 
Company presentation ppt
Company presentation pptCompany presentation ppt
Company presentation ppt
 
Mercados verdes en colombia
Mercados verdes en colombiaMercados verdes en colombia
Mercados verdes en colombia
 

Ähnlich wie sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)

Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)jeffz
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersMiles Sabin
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersMiles Sabin
 
The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015rvagg
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersSkills Matter
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersMiles Sabin
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
楽々Scalaプログラミング
楽々Scalaプログラミング楽々Scalaプログラミング
楽々ScalaプログラミングTomoharu ASAMI
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumNgoc Dao
 
Json - ideal for data interchange
Json - ideal for data interchangeJson - ideal for data interchange
Json - ideal for data interchangeChristoph Santschi
 
Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016DesertJames
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Ramamohan Chokkam
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android DevelopmentSpeck&Tech
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java ProgrammersEric Pederson
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojureAbbas Raza
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 

Ähnlich wie sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver) (20)

Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
Json the-x-in-ajax1588
Json the-x-in-ajax1588Json the-x-in-ajax1588
Json the-x-in-ajax1588
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Scala Introduction
Scala IntroductionScala Introduction
Scala Introduction
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
楽々Scalaプログラミング
楽々Scalaプログラミング楽々Scalaプログラミング
楽々Scalaプログラミング
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Json - ideal for data interchange
Json - ideal for data interchangeJson - ideal for data interchange
Json - ideal for data interchange
 
Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 

Mehr von Eugene Yokota

Equality in Scala (ScalaMatsuri 2020)
Equality in Scala (ScalaMatsuri 2020)Equality in Scala (ScalaMatsuri 2020)
Equality in Scala (ScalaMatsuri 2020)Eugene Yokota
 
sbt: core concepts and updates (Scala Love 2020)
sbt: core concepts and updates (Scala Love 2020)sbt: core concepts and updates (Scala Love 2020)
sbt: core concepts and updates (Scala Love 2020)Eugene Yokota
 
Analysis of Zinc (nescala 2020)
Analysis of Zinc (nescala 2020)Analysis of Zinc (nescala 2020)
Analysis of Zinc (nescala 2020)Eugene Yokota
 
Analysis of Zinc (ScalaSphere 2019)
Analysis of Zinc (ScalaSphere 2019)Analysis of Zinc (ScalaSphere 2019)
Analysis of Zinc (ScalaSphere 2019)Eugene Yokota
 
sbt core concepts (ScalaMatsuri 2019)
sbt core concepts (ScalaMatsuri 2019)sbt core concepts (ScalaMatsuri 2019)
sbt core concepts (ScalaMatsuri 2019)Eugene Yokota
 
pull requests I sent to scala/scala (ny-scala 2019)
pull requests I sent to scala/scala (ny-scala 2019)pull requests I sent to scala/scala (ny-scala 2019)
pull requests I sent to scala/scala (ny-scala 2019)Eugene Yokota
 
sbt server (LSP discussion, 2018 Jan)
sbt server (LSP discussion, 2018 Jan)sbt server (LSP discussion, 2018 Jan)
sbt server (LSP discussion, 2018 Jan)Eugene Yokota
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Eugene Yokota
 

Mehr von Eugene Yokota (10)

Equality in Scala (ScalaMatsuri 2020)
Equality in Scala (ScalaMatsuri 2020)Equality in Scala (ScalaMatsuri 2020)
Equality in Scala (ScalaMatsuri 2020)
 
sbt: core concepts and updates (Scala Love 2020)
sbt: core concepts and updates (Scala Love 2020)sbt: core concepts and updates (Scala Love 2020)
sbt: core concepts and updates (Scala Love 2020)
 
Analysis of Zinc (nescala 2020)
Analysis of Zinc (nescala 2020)Analysis of Zinc (nescala 2020)
Analysis of Zinc (nescala 2020)
 
Analysis of Zinc (ScalaSphere 2019)
Analysis of Zinc (ScalaSphere 2019)Analysis of Zinc (ScalaSphere 2019)
Analysis of Zinc (ScalaSphere 2019)
 
sbt core concepts (ScalaMatsuri 2019)
sbt core concepts (ScalaMatsuri 2019)sbt core concepts (ScalaMatsuri 2019)
sbt core concepts (ScalaMatsuri 2019)
 
pull requests I sent to scala/scala (ny-scala 2019)
pull requests I sent to scala/scala (ny-scala 2019)pull requests I sent to scala/scala (ny-scala 2019)
pull requests I sent to scala/scala (ny-scala 2019)
 
sbt 1
sbt 1sbt 1
sbt 1
 
sbt server (LSP discussion, 2018 Jan)
sbt server (LSP discussion, 2018 Jan)sbt server (LSP discussion, 2018 Jan)
sbt server (LSP discussion, 2018 Jan)
 
Thinking in Cats
Thinking in CatsThinking in Cats
Thinking in Cats
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)
 

Kürzlich hochgeladen

Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntelliSource Technologies
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionsNirav Modi
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmonyelliciumsolutionspun
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeNeo4j
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfBrain Inventory
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.Sharon Liu
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxAutus Cyber Tech
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIIvo Andreev
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorShane Coughlan
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Jaydeep Chhasatia
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxJoão Esperancinha
 
Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Incrobinwilliams8624
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 

Kürzlich hochgeladen (20)

Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptx
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspections
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in Trivandrum
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdf
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptx
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AI
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS Calculator
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
 
Salesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptxSalesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptx
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptx
 
Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Inc
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 

sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)

  • 1. sbt, history of JSON libraries, microservices, and schema evolution Eugene Yokota (@eed3si9n)
 February, 2017
  • 2. • Scala hobbyist since 2010 • scalaxb (XML data binding) • treehugger.scala • sbt-assembly, sbt-buildinfo, etc • “learning Scalaz” / “herding Cats” • ScalaMatsuri • Lightbend/Typesafe since 2014 • tech lead of Reactive Platform team • current maintainer / tech lead of sbt who is this guy (@eed3si9n)?
  • 6. • How do you scale a technological organization? • Goal: Sustainable development development at scale
  • 7. • Bezos mandate (written circa 2002 before AWS) https://plus.google.com/ +RipRowan/posts/eVeouesvaVX microservice is a social stack 1. All teams will henceforth expose their data and functionality through service interfaces. 2. Teams must communicate with each other through these interfaces. 3. There will be no other form of inter-process communication allowed: no direct linking, no direct reads of another team’s data store, no shared-memory model, no back-doors whatsoever. The only communication allowed is via service interface calls over the network. 4. It doesn’t matter what technology they use. HTTP, Corba, Pubsub, custom protocols -- doesn't matter. Bezos doesn't care. 5. All service interfaces, without exception, must be designed from the ground up to be externalizable. That is to say, the team must plan and design to be able to expose the interface to developers in the outside world. No exceptions. 6. Anyone who doesn't do this will be fired.
  • 8. Brief history of JSON libraries Eugene Yokota (@eed3si9n)
 2016
  • 9. Brief history of JSON libraries Dispatch JSON literaljson Lift JSON sjson Spray JSON Play JSON Argonaut json4s Circe Jawn SLIP-28 JSON Rapture JSON sjson-new 2009 2010 2014
  • 10. 2008
  • 12. Programming in Scala import scala.util.parsing.combinator._ class JSON extends JavaTokenParsers { def value : Parser[Any] = obj | arr | stringLiteral | floatingPointNumber | "null" | "true" | "false" def obj : Parser[Any] = "{"~repsep(member, ",")~"}" def arr : Parser[Any] = "["~repsep(value, ",")~"]" def member: Parser[Any] = stringLiteral~":"~value } https://www.artima.com/pins1ed/combinator-parsing.html#31.4
  • 13. • Chapter 5. Writing a library: working with JSON data Real World Haskell data JValue = JString String | JNumber Double | JBool Bool | JNull | JObject [(String, JValue)] | JArray [JValue] deriving (Eq, Ord, Show)
  • 14. 2009
  • 15. • https://github.com/dispatch/dispatch/commit/ 41edb939baa5c6edb4378c1bd8e1d2f10f3350f2 • Contributed by Jorge Ortiz • Parsing using parser combinator • Values stored in AST, JsValue Dispatch JSON
  • 16. • https://github.com/jonifreeman/literaljson • Authored by Joni Freeman • Custom parser • Values stored in AST, JValue • On August 11, 2009, Joni contributed literaljson to Lift, and became Lift-JSON jonifreeman/literaljson
  • 17. 2010
  • 18. • https://github.com/debasishg/sjson • Authored by Debasish Ghosh • sjson: Now offers Type Class based JSON Serialization in Scala • Uses Dispatch JSON for AST sjson
  • 20. • Allows adding capability to a class after the fact in a typesafe manner. Typeclass trait Eq[A] {   def equals(x: A, y: A): Boolean } • Eq typeclass can enable === operator to compare only the supported types, and prevent compilation of "1" === 1 • Scala Implicits : Type Classes Here I Come
  • 21. JsonFormat trait CanRead[A] {   def reads(json: JsValue): A } trait CanWrite[A] {   def writes(a: A): JsValue } trait JsonFormat[A] extends CanRead[A] with CanWrite[A] implicit val intFormat: JsonFormat[Int] = ...
  • 22. JsonFormat • JsonFormat typeclass allows conversion to and from an arbitrary type to a JSON AST.
  • 23. 2011
  • 24. • https://github.com/spray/spray-json • Authored by Mathias Dönitz • Original parser • Ported AST from Dispatch JSON and type classes from sjson spray-json
  • 25. • https://github.com/playframework/playframework/commit/ 63448578b15dcc7bf4806878c7b3aa4c74193af6 • Started out as port of Dispatch JSON and sjson typeclasses, but quickly added its own implementations. Play JSON
  • 26. 2012
  • 27. • http://argonaut.io/ • Purely functional JSON library • Authored by Mark Hibberd, Tony Morris, Sean Parsons • Uses Scalaz or Cats • Very feature rich (Lenses, Cursor, History Cursor) Argonaut
  • 28. 2013
  • 29. • https://github.com/json4s/json4s • Fork of Lift-json. JSON library that is not strongly tied to a web framework. json4s
  • 30. 2014
  • 31. • https://github.com/non/jawn • Authored by Erik Osheim (@d6) • Backend-independent JSON parser Jawn
  • 32. • http://rapture.io/mod/json • Authored by Jon Pretty • Backend-independent JSON library Rapture JSON
  • 33. 2015
  • 34. • https://github.com/travisbrown/circe • Authored by Travis Brown • Port of Argonaut Circe
  • 35. 2016
  • 36. • https://github.com/mdedetrich/scala-json-ast • Authored by Matthew de Detrich • Aiming to be the common JSON AST Scala JSON AST (SLIP-28)
  • 37. • https://github.com/eed3si9n/sjson-new • Backend-independent typeclass based JSON codec • No macros sjson-new
  • 38. Brief history of JSON libraries Dispatch JSON literaljson Lift JSON sjson Spray JSON Play JSON Argonaut json4s Circe Jawn SLIP-28 JSON Rapture JSON sjson-new 2009 2010 2014
  • 40. • “Serialization” tends to start from a programming language construct, and it generates String or byte array. • Data binding starts with a contract or a schema of the wire format, and generates the binding in a programming language. • XML Schema / WSDL • Google Protocol Buffer • Apache Thrift • Apache Avro • Facebook GraphQL Serialization vs Data binding
  • 41. • sealed traits • case classes Representing data in Scala
  • 42. • sealed traits • case classes Representing data in Scala Cannot evolve in a binary compatible way.
  • 43. Representing data in Scala class Greeting(name: String) {   def copy(name: String = name): Greeting = ???   def unapply(v: Greeting): Option[String] = ??? } class Greeting(name: String, x: Int) {   def copy(name: String = name, x: Int = x): Greeting = ???   def unapply(v: Greeting): Option[(String, Int)] = ??? }
  • 44. • sealed traits • case classes • Cannot evolve in a binary compatible way. • But generating equals, hash, and toString is generally useful. Representing data in Scala
  • 46. • http://www.scala-sbt.org/contraband/ • Contraband is a description language for your datatypes and APIs, currently targeting Java and Scala. • Based on GraphQL schema. Contraband
  • 47. Record types package com.example @target(Scala) ## Character represents the characters in Star Wars. type Character { name: String! appearsIn: [com.example.Episode]! }
  • 48. @since annotation package com.example @target(Scala) type Greeting { value: String! x: Int @since("0.2.0") }
  • 49. Enumeration types package com.example @target(Scala) ## Star Wars trilogy. enum Episode { NewHope Empire Jedi }
  • 50. Interfaces package com.example @target(Scala) ## Character represents the characters in Star Wars. interface Character { name: String! appearsIn: [com.example.Episode]! friends: lazy [com.example.Character] }
  • 51. Record type example package com.example @target(Scala) type Person { name: String! age: Int }
  • 52. Record type example // DO NOT EDIT MANUALLY package com.example final class Person private (   val name: String,   val age: Option[Int]) extends Serializable {   override def equals(o: Any): Boolean = o match {     case x: Person => (this.name == x.name) && (this.age == x.age)     case _ => false   }   override def hashCode: Int = {     37 * (37 * (17 + name.##) + age.##)   }   override def toString: String = {
  • 53. Record type example   override def toString: String = {     "Person(" + name + ", " + age + ")"   }   protected[this] def copy(name: String = name, age: Option[Int] = age): Person = {     new Person(name, age)   }   def withName(name: String): Person = {     copy(name = name)   }   def withAge(age: Option[Int]): Person = {     copy(age = age)   }   def withAge(age: Int): Person = {
  • 54. Record type example object Person {   def apply(name: String, age: Option[Int]): Person = new Person(name, age)   def apply(name: String, age: Int): Person = new Person(name, Option(age)) }
  • 55. Record type example > val x = Person("Alice", 20) > x.withAge(21)
  • 56. Contraband can derive sjson-new codecs
  • 57. JSON codec generation package com.example @target(Scala) type Person { name: String! age: Int }
  • 58. JSON codec generation package generated import _root_.sjsonnew.{ deserializationError, serializationError, Builder, JsonFormat, Unbuilder } trait PersonFormats { self: sjsonnew.BasicJsonProtocol =>   implicit lazy val personFormat: JsonFormat[_root_.Person] = JsonFormat[_root_.Person] {     override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.Person = {       jsOpt match {         case Some(js) =>           unbuilder.beginObject(js)           val name = unbuilder.readField[String]("name")           val age = unbuilder.readField[Option[Int]]("age")           unbuilder.endObject()           _root_.Person(name)
  • 59. JSON codec generation scala> import sjsonnew.support.scalajson.unsafe.{ Converter, CompactPrinter, Parser } scala> import com.example.codec.CustomJsonProtocol._ scala> import com.example.Person scala> val p = Person("Bob", 20) p: com.example.Person = Person(Bob, 20) scala> val j = Converter.toJsonUnsafe(p) j: scala.json.ast.unsafe.JValue = JObject([Lscala.json.ast.unsafe.JField;@6731ad72) scala> val s = CompactPrinter(j) s: String = {"name":"Bob","age":20} scala> val x = Parser.parseUnsafe(s)
  • 60. JSON codec generation scala> val s = CompactPrinter(j) s: String = {"name":"Bob","age":20} scala> val x = Parser.parseUnsafe(s) x: scala.json.ast.unsafe.JValue = JObject([Lscala.json.ast.unsafe.JField;@7331f7f8) scala> val q = Converter.fromJsonUnsafe[Person](x) q: com.example.Person = Person(Bob, 20) scala> assert(p == q)
  • 61. • http://www.scala-sbt.org/contraband/ • Contraband is a description language for your datatypes and APIs, currently targeting Java and Scala. • Low-tech metaprogramming (code generation) • Binary compatible evolution of pseudo case class. • Auto derivation of backend-independent JSON codec. Contraband
  • 62. • An opportunity for datatype-generic programming. • For example, one backend is Int Contraband
  • 63. • An opportunity for datatype-generic programming. • For example, one backend is Int (Murmurhash support) • Builder API is used to build one-way hash. Contraband