commercetools / commercetools/sphere-scala-libs
Deserialisation of embedded optional type hinted sum types
- Dominant language
- Scala
- Stars
- 22
- Forks
- 7
- Avg merge
- 18h 43m
- Merged PRs (30d)
- 20
Description
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`.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at package.scala:74 and locate the test described as "should support the absence of optional embedded type hinted attributes." Reproduce the deserialization of the JSON with only the name field, then add or update regression coverage so the embedded TypeHintEnum field is set to None instead of raising the missing type-field error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100