immutables icon indicating copy to clipboard operation
immutables copied to clipboard

Jackson serialization missing values

Open alexwen opened this issue 11 years ago • 3 comments

I have several types much like this:

@Value.Immutable
@JsonDeserialize(as = ImmutableAssetData.class)
@JsonSerialize(as = ImmutableAssetData.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class AssetData implements ApiData {
    public static final String TYPE = Types.ASSET;
    @Override
    public String getType() {
        return TYPE;
    }

With 2.0.18 they are no longer being serialized properly as type isn't available on the JSON object in ImmutableAssetData. In other words, I expect it to be serialized but don't really care about the value on deserialization.

I was able to get it to include it by specifying Value.Derived and Value.Auxillary, is that the required/expected condition from here on out? It seems to me that this new functionality, although it is mostly likely more performant, is masking some of the nicer features of Jackson.

It also breaks backwards compatibility in this case and makes upgrading a bit of a pain, though not impossible as there is a workaround.

alexwen avatar Aug 28 '15 22:08 alexwen

Thank you for reporting the issue. Sorry for the unintended functionality breakage. The functionality you referring to was working merely by chance, and could only work one way (serialization, but not deserialization). We've tested only serialization and deserialization of values that are considered as attributes by Immutables, and not for plain getter methods. So, probably, Derived (with or without Auxillary) is a way to go in this situation.

Having that said, I really don't know how to qualify if it became better or worse with regard to the richness of Jackson integration. On one hand the implementation change allowed to resolve conflicts when one uses advanced jackson features such as custom serializers etc. On the other hand, now it breaks to serialized non-attribute accessors and in your case. If there are more other negative factors in new implementation, it may be possible to revert conditionally or unconditionally to the previous implementation. Other outcome may be documenting of this behavior to stress that non-attribute accessors (in terms of Immutables) will not be serialized by Jackson as it works with the POJO or bean.

elucash avatar Aug 29 '15 08:08 elucash

When I get some more time this week I will investigate if there are any other side-effects that our tests pick up and post here.

On a side note, the change in behavior was a bit surprising as it was a fix release (if you are using semantic versioning), and also, I found no mention of it in the changelog: https://github.com/immutables/immutables/issues?q=milestone%3A2.0.18+is%3Aclosed

Overall, I have been very impressed with the library, its quality, and its great documentation. So, thank you!

alexwen avatar Aug 30 '15 15:08 alexwen

Previous behavior restored! Released in 2.1.0

elucash avatar Oct 24 '15 03:10 elucash