Skip to content
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

Added addSerializer and addDeserializer extensions to SimpleModule for registering KClasses #322

Merged
merged 5 commits into from
Apr 27, 2020

Conversation

Neuman968
Copy link

Added extension methods for adding custom serializers and deserializers for a Kotlin KClass that adds both the java class and java type as bound classes.

This allows for registering serializers like

    val objectMapper = jacksonObjectMapper()
            .registerModule(SimpleModule()
                    .addSerializer(Double::class, RoundingSerializer())
                    .addDeserializer(Double::class, RoundingDeserializer()))

Instead of

    val objectMapper = jacksonObjectMapper()
            .registerModule(SimpleModule()
                    .addSerializer(Double::class.javaObjectType, RoundingSerializer())
                    .addSerializer(Double::class.java, RoundingSerializer())
                    .addDeserializer(Double::class.javaObjectType, RoundingDeserializer())
                    .addDeserializer(Double::class.java, RoundingDeserializer()))

Hopefully this can be useful. Thank you for your time and for the awesome project!

…r accepting KClass and registering both the java class, and javaObjectType for the KClass.
@dinomite dinomite changed the base branch from 2.10 to master April 26, 2020 19:34
@dinomite
Copy link
Member

Great improvement! Would you add your info to the release-notes/VERSION-2.x and release-notes/CREDITS-2.x? I'll get this merged to master and it will go out as part of 2.12.

@dinomite
Copy link
Member

Ack—I've done it a bit wrong. Just realized that master is tracking Jackson 3.0.0, so I'll fix up the commits I made to put this back on the 2.x tree…

@dinomite dinomite changed the base branch from master to 2.12 April 26, 2020 20:04
@Neuman968
Copy link
Author

@dinomite Thank you for your review! I tried to follow the targeted branches from other PR's out from this project. I originally target it for master but wasn't sure so I changed it to 2.12. I just updated the PR to update release-notes/VERSION-2.x and release-notes/CREDITS-2.x Let me know if there is anything else, glad I can help!

@dinomite
Copy link
Member

You did it right, it was my own confusion—I'm still learning the ropes on this project.

@dinomite dinomite merged commit 2fe15db into FasterXML:2.12 Apr 27, 2020
@Neuman968 Neuman968 deleted the addSerializerExtensions branch April 27, 2020 18:07
@dinomite
Copy link
Member

@Neuman968 I forgot to have you sign the CLA—would you fill this out and email a scan/photo of the result to info at fasterxml dot com?

https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants