Skip to content

Instantly share code, notes, and snippets.

@paul-lysak
Created August 3, 2016 17:14
Show Gist options
  • Save paul-lysak/37440713a88fb58d272c742389760437 to your computer and use it in GitHub Desktop.
Save paul-lysak/37440713a88fb58d272c742389760437 to your computer and use it in GitHub Desktop.
package sample
import org.json4s.jackson.Serialization
/**
*
* Created by Paul Lysak on 03.08.16.
*/
object EnumDemo {
def main(args: Array[String]): Unit = {
val d1 = SampleData(name = "first foo", version = FooVersion.V1)
println("original: " + d1)
// implicit val formats = Serialization.formats(NoTypeHints)
implicit val formats = org.json4s.DefaultFormats +
new org.json4s.ext.EnumNameSerializer(FooVersion) +
new org.json4s.ext.EnumNameSerializer(BarVersion)
val s1 = Serialization.write(d1)
println("serialized: " + s1)
val ds1 = Serialization.read[SampleData](s1)
println("deserialized: " + ds1)
//Turns out to be false!
println("original == deserialized: " + (d1 == ds1))
}
}
/*
name := "scala_enums"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"org.json4s" %% "json4s-jackson" % "3.4.0",
"org.json4s" %% "json4s-ext" % "3.4.0"
)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment