-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Traits and JsonCodecMaker #247
Comments
jsoniter-scala derives codecs only for sealed traits. Generally it is done for security reasons to avoid generation of codecs for unwanted implementations (which can presents in the compilation classpath) of generic traits like Also, during code generation the Here is how it works for sealed trait:
Another option is to use wrapping by discriminator JSON object instead of the
|
BTW, if models for serialization to XML and JSON differs too much then you can consider an ability to generate a separate model tree for JSON representation from some JsonSchema. Also, a mapping between model trees can be defined by the Chimney library to avoid most of boilerplate. Yet another option would be writing of custom codecs or a custom macro for their generation... Here is example of custom codecs for a simple model: https://github.com/plokhotnyuk/jsoniter-scala/blob/master/jsoniter-scala-core/src/test/scala/com/github/plokhotnyuk/jsoniter_scala/core/UserAPI.scala |
@plokhotnyuk ..once again, i appreciate the prompt and thorough response. as you may have probably guessed...just like in my other question, i am using scalaxb to generate the case classes...and it seems that this can be addressed by making the base trait generated as sealed (i opened a ticket or hey maybe i'll attempt to make a PR for that ticket...god help us) |
This is perhaps a general misunderstanding on how the
JsonCodecMaker
works, but i'm struggling with using the macro when one field is atrait
rather than acase class
. consider this example:when i use the macro:
i get a compile time error:
i'm not entirely sure how to get around this or if i've hit a limitation to what the macro can do.
thank you.
The text was updated successfully, but these errors were encountered: