Deserialzing using static method for types of a given super class #237
-
I Already asked the same question on stackoverflow I provided a sample project on GitHub to showcase my problem: I would like to configure to use a static method during deserialization of classes that extend AbstractCodestable (or implements the interface Codestable). How is this possible and if there are multiple solutions, what are the pros and cons? In my project there are some base classes:
There are also some codestable implementation classes
Imagine that in real the base classes are defined in a maven module "base". The codestable implementation classes are generated in another maven module "codestable". The "base" module DOES NOT depend on "codestable" (and therefore does not know these classes). The "codestable" module" depends on the "base" module. I would like to configure Jackson's ObjectMapper (or the Currently the following exception occurs:
I can adjust all the classes as I want, but actually
Is there any way to let Jackson know how to deserialize the codestable classes? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Jackson let's you write your own custom serializers and deserializers. |
Beta Was this translation helpful? Give feedback.
-
Some notes:
I don't think you can get what you are asking for, out of the box, but there are a few pieces that combined might allow it. |
Beta Was this translation helpful? Give feedback.
-
I solved this by adding the @JsonCreator annotation to all concrete codestable classes e.g.
As the codestable classes are generated and I am able to adjust the generator this seems to be the easiest solution for me in this case. |
Beta Was this translation helpful? Give feedback.
I solved this by adding the @JsonCreator annotation to all concrete codestable classes e.g.
As the codestable classes are generated and I am able to adjust the generator this seems to be the easiest solution for me in this case.