0

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?

tkroman
  • 4,751
  • 1
  • 24
  • 43

1 Answers1

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
  • 2
    Here's the issue, for any newcomers https://github.com/FasterXML/jackson-databind/issues/494 – Emerson Farrugia Sep 24 '14 at 13:47