Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialisation of embedded optional type hinted sum types #429

Open
nolledge opened this issue Sep 2, 2022 · 1 comment
Open

Deserialisation of embedded optional type hinted sum types #429

nolledge opened this issue Sep 2, 2022 · 1 comment

Comments

@nolledge
Copy link
Contributor

nolledge commented Sep 2, 2022

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.

@nolledge
Copy link
Contributor Author

nolledge commented Sep 6, 2022

Added a test here: 0ee1f85 (name: support the absence of optional embedded type hinted attributes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant