Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
is now
This means that specific JsonValue subtypes are not lost when using a
ToJson[A]
type annotation (instead of eg.ToJsonValue[A, JsonString]
).ToJsonValue
is preserved as an aux typeThis is especially helpful with cases like
where object methods would not normally be available without specifying the type as
ToSomeJsonObject[MyClass]
or when
ToJson
instances are derived from others and wish to maintain the JSON type of the instances they're derived from. For exampleHowever this has an quirk where the type of the wrapper must be annotated as a
ToJsonValue
like belowThe downside is that instances can no longer be defined with lambda syntax and need to be wrapped in a
ToJson.apply()
constructor (although only in scala 2)all of the above were initial thoughts. I am now thinking to scrap the whole PR. Here's why:
as stated in that last bit, you need to use
ToJsonValue
if you want to preserve the specificJsonValue
subtype. you can also simply omit the type annotation, and type inference will take care of you. some examples that work OKimplicit def optionToJson[A: ToJson] = ToJson((: Option[A]).flatMap(.toJson))
however simply
ToJson
does not preserve the subtypethis is... exactly the same as the behavior before but uses one less generic parameter. one case where that matters:
would become
and now requires knowledge of the output type if you don't want to lose it when calling explicitly. ie.
optionToJson[Int]
vsoptionToJson[Int, JsonNumber]
so passing this PR requires determining that the above use case is worth the trouble