commercetools / commercetools/sphere-scala-libs

Type hint field annotation on sealed trait enums

Open
#431 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
22
Forks
7
Avg merge
18h 43m
Merged PRs (30d)
20

Description

The @JSONTypeHintField and @MongoTypeHintField annotations are **only** respected on sealed traits when they are present on each variation of that type. For `sealed abstract classes` it is sufficient to only put the annotation on the base-class.

I created a test scenarios here: https://github.com/commercetools/sphere-scala-libs/commit/0ee1f85f4e3c8c464740b36461831012ef97d348

The tests "JSONTypeHintField must be respected when only defined on sealed trait base-class" and "JSONTypeHintField must be respected when only defined on abstract class base-class"

in [json/json-derivation/src/test/scala/io/sphere/json/generic/JsonTypeHintFieldSpec.scala](https://github.com/commercetools/sphere-scala-libs/commit/0ee1f85f4e3c8c464740b36461831012ef97d348#diff-c925fbafdf8760bfaba038877aec476f2fda01c8e61a7e2a45b1fa1f107a0759)

Show this difference in behaviour.

This commit also contains a test for the Mongo codec in an embedded context [mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/MongoEmbeddedSpec.scala](https://github.com/commercetools/sphere-scala-libs/commit/0ee1f85f4e3c8c464740b36461831012ef97d348#diff-d2718ac5b71261d821946a1fd1a10e2aa965a59f2bf186936eedfa0a04b65b38)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with json/json-derivation/src/test/scala/io/sphere/json/generic/JsonTypeHintFieldSpec.scala and run the tests named in the issue to compare sealed traits with sealed abstract classes. Then inspect mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/MongoEmbeddedSpec.scala for the corresponding Mongo scenario. Done means the annotations work when defined only on the sealed base type and the affected tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, scala
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.