Skip to content

Deserialisation of embedded optional type hinted sum types #429

Description

@nolledge

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions