Skip to content

Instantly share code, notes, and snippets.

@akehoyayoi
Created July 29, 2013 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akehoyayoi/6102407 to your computer and use it in GitHub Desktop.
Save akehoyayoi/6102407 to your computer and use it in GitHub Desktop.
json4s(lift-json)がバグってる件
// "org.json4s" %% "json4s-native" % "3.2.4"
import org.json4s._
import org.json4s.native.Serialization._
case class AAA(a : Option[Long],b : Option[Long],c : Option[Long])
object JsonTest {
def toJson[Value <: AnyRef](any : Value) : String = {
write(any)(DefaultFormats)
}
}
/*
scala> JsonTest.toJson(AAA(Some(1),Some(2),Some(3)))
res0: String = {"a":1,"b":2,"c":3}
scala> JsonTest.toJson(AAA(Some(1),Some(2),None))
res1: String = {"a":1,"b":2}
scala> JsonTest.toJson(AAA(Some(1),None,Some(3)))
res2: String = {"a":1,"c":3}
scala> JsonTest.toJson(AAA(None,Some(2),Some(3)))
res3: String = {,"b":2,"c":3} // <- wrong format
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment