You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the type is generic (e.g. Foo<T>) then its builder is also likely generic (e.g. Foo$Builder<T>). In such a case there is inevitably a setter on the builder that takes T (e.g. public void setBar(final T value)). When you deserialize json into such a type you do so with a type reference (e.g. new TypeReference<Foo<Bar>>(){}. Although the resulting pojo is constructed via its builder the provided type reference is for the resulting type and not its builder.
There is a bug in Jackson where the type binding information from the type reference is not carried over to the builder. Consequently, when deserializing content for setBar the type of the value is undetermined and is therefore deserialized by default as a TreeMap. The issue in Jackson is: FasterXML/jackson-databind#921
In such situations the recommended work around is to deserialize into the builder and then manually call build. This is easy if the generic type is at the top level; however, if it's buried in the type hierarchy you would need to use a custom serializer to achieve this same result at the desired level.
Tests were added for a generic and non-generic round-trip with builders through Jackson in #16. The generic test is disabled because it fails, but can be used to prove the resolution of this issue.
The text was updated successfully, but these errors were encountered:
If the type is generic (e.g.
Foo<T>
) then its builder is also likely generic (e.g.Foo$Builder<T>
). In such a case there is inevitably a setter on the builder that takes T (e.g.public void setBar(final T value)
). When you deserialize json into such a type you do so with a type reference (e.g.new TypeReference<Foo<Bar>>(){}
. Although the resulting pojo is constructed via its builder the provided type reference is for the resulting type and not its builder.There is a bug in Jackson where the type binding information from the type reference is not carried over to the builder. Consequently, when deserializing content for
setBar
the type of the value is undetermined and is therefore deserialized by default as aTreeMap
. The issue in Jackson is: FasterXML/jackson-databind#921In such situations the recommended work around is to deserialize into the builder and then manually call
build
. This is easy if the generic type is at the top level; however, if it's buried in the type hierarchy you would need to use a custom serializer to achieve this same result at the desired level.Tests were added for a generic and non-generic round-trip with builders through Jackson in #16. The generic test is disabled because it fails, but can be used to prove the resolution of this issue.
The text was updated successfully, but these errors were encountered: