-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add ability to control type encoding #5
Conversation
So I thought about all that. I think I'd prefer not to introduce an intermediary implicit ( I began to refactor argonaut-shapeless so that it would be easier to generate codecs that behave a bit differently than the default ones, see argonaut-shapeless/src/test/scala/argonaut/JsonCodecs.scala Lines 17 to 27 in bd1f2ba
in particular. I think it should be possible to achieve what you'd like by supplying different implicits to encode ccons cells. That would amount to replace cconsJsObjectEncodeJson and cconsAsJsObjectDecodeJson by custom implicits in the former link.
These changes would be for argonaut-shapeless 0.3 (I'll publish snapshot versions as soon as shapeless 2.2 final is out). Would it be ok for you to do it this way? I'd also be keen to add extra codecs, but the one you added in the tests doesn't feel general enough to me for that. I was more thinking about the same without the |
Yep importing different |
I was thinking ultimately about putting alternate sets of implicits like these in other objects whose content could be imported instead of But for truly custom ways of handling sum types, it has to be a bit more complicated... |
I think the changes should consist in:
trait JsonCoproductCodec {
def encode(typeName: String, json: Json): Json
def attemptDecode[T](typeName: String, decodeJson: DecodeJson[T], json: Json): Option[DecodeResult[T]]
} (which changes a little the logic of decoding compared to your
These are pretty big changes (which can be discussed). Tell me if you'd prefer me to take care of them. |
About the changes in |
Nice! I was thinking of example when I may need to override Regarding refactoring. I think I can handle that. Gonna take some time though. Like until this friday. |
Great! I may throw away the basis of |
About the application of |
Nice one too! |
@alexarchambault Hi! I'm kinda confused about how |
The obvious part is that these methods should be reused in both Custom and Automatic variants. |
Not much time for a detailed answer now, but:
Maybe you should just submit a new PR against |
That's detailed enough ) thanks, I got it! Will do! |
Sometimes it is needed to change how type is being encoded in json result. So I implemented it using implicit
CoproductContainer
parameter. Previous behavior is persisted. So it’s non breaking change.