Jackson is demanding the public modifier on a no-arg constructor, while jdk8's Optional provides only static methods. What are the possible workarounds? And in general, if I have to use a a 3rd party library providing classes following this pattern, what should I do?
Asked
Active
Viewed 706 times
0
tkroman
- 4,751
- 1
- 24
- 43
-
http://stackoverflow.com/questions/11838039/jackson-3rd-party-class-with-no-default-constructor ? – Brian Roach Jan 13 '14 at 18:08
-
@BrianRoach, I still don't get how to make use of that in case of a generic type. – tkroman Jan 13 '14 at 19:33
1 Answers
1
No, Jackson does NOT require a public no-arg constructor; any access level (even private) will work. But it does require a no-arg constructor if no custom deserializer is provided.
What is needed for new types, in general are extension modules. There are actually plans to add a "JDK8 module", since core Jackson only requires 1.6 currently, and baseline is unlikely to move in near future. But adding support for new types should be relatively easy: Jackson Guava datatype module (https://github.com/FasterXML/jackson-datatype-guava) for example, adds support for Guava's optional. You may be able to copy deserializer from there in the meantime, use it via SimpleModule you define.
StaxMan
- 108,392
- 32
- 202
- 235
-
Thank you, this link is a helpful one. Since there is no significant difference, I'm going to implement something like that while there is no support for this stuff out-of-the-box. – tkroman Jan 13 '14 at 22:12
-
2Here's the issue, for any newcomers https://github.com/FasterXML/jackson-databind/issues/494 – Emerson Farrugia Sep 24 '14 at 13:47