Created
August 3, 2016 17:14
-
-
Save paul-lysak/37440713a88fb58d272c742389760437 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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