I am using Jackson 2.1.3. My goal is to use some default value for the field when deserializing the bean from JSON. In particular, I write in Scala, so I want the deserializer to use the default value for the field if the field is not specified in JSON, but the default value is specified in the constructor of the scala class. I can get the default value at runtime for a known constructor and index or the name of a missing parameter, but I cannot find a way to use this value in a bean deserializer.
I know that this problem was solved in Jerkson, but firstly, I canโt use it because it does not work on scala 2.10, and secondly, they solved it using their own deserializer for case classes, instead from Jacksons BeanDeserializer - so they lose some of Jackson's basic features.
I tried using AnnotationIntrospector with a specific findDeserializer method. I am extending DelegatingDeserializer with a custom "getNullValue", but there was a problem with the delegate - I did not find a way to get a good deserializer in the context of the findDeserializer method without losing type information.
Then I spend a lot of time reading Jackson's sources, and I have not found a way to provide default values โโfor fields in bean deserialization, without copying to half of Jackson's library with weakened access modifiers across multiple fields.
source share