sphere-scala-libs
sphere-scala-libs copied to clipboard
Deserialisation of embedded optional type hinted sum types
Given this sum type with a type hint field, optionally embedded in a test class:
@JSONTypeHintField
sealed abstract class TypeHintEnum
case object Varialtion1 extends TypeHintEnum
case object Varialtion2 extends TypeHintEnum
object TypeHintEnum {
implicit val json: JSON[TypeHintEnum] = deriveJSON[TypeHintEnum]
}
case class Test5(name: String, @JSONEmbedded embedded: Option[TypeHintEnum])
object Test5 {
implicit val json: JSON[Test5] = jsonProduct(apply _)
}
The desieralisation of this json to the test class
"""{ "name": "ze name" }"""
Fails like this:
[info] - should support the absence of optional embedded type hinted attributes *** FAILED *** (24 milliseconds)
[info] io.sphere.json.JSONException: Missing type field 'type' in '{"name":"ze name"}'
[info] at io.sphere.json.package$.getFromJValue(package.scala:74)
[info] at io.sphere.json.package$.getFromJSON(package.scala:60)
[info] at io.sphere.json.package$.getFromJSON(package.scala:63)
Instead of setting the embedded field to None.
Added a test here: https://github.com/commercetools/sphere-scala-libs/commit/0ee1f85f4e3c8c464740b36461831012ef97d348 (name: support the absence of optional embedded type hinted attributes)