jackson-datatype-hibernate icon indicating copy to clipboard operation
jackson-datatype-hibernate copied to clipboard

Add feature `WRAP_IDENTIFIER_IN_OBJECT` to allow disabling of wrapping of "id" attribute

Open jobosk opened this issue 4 years ago • 3 comments

I've noticed that Feature SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS works as inteded (serializing attributes from the Hibernate proxy of lazy loaded objects, i.e. identifiers), but wrapped like this:

{ "id" : 1 }

This means the (lazy) relation to Foo in the following object would be serialized as:

{ ... , foo: { "id" : 1 }, ... }

I have found standard behaviour to be the following:

{ ... , foo: 1, ... }

For example, when using "@JsonIdentityInfo" annotation, Jackson would resolve relations as numeric IDs to break circular dependencies (i.e. the entity has already been visited and fully serialized).

I would like to know if this is a known issue or is it just me that finds odd the default behaviour. But anyway, I'd be happy to implement a new backwards-compatible feature to achieve it.

jobosk avatar Jul 01 '20 19:07 jobosk

I don't really know the answer as this module in general, and feature in particular, came as contribution. So the feature for making wrapping optional sounds reasonable.

cowtowncoder avatar Jul 08 '20 02:07 cowtowncoder

As per notes on PR #137 will be merging as soon as we get CLA.

cowtowncoder avatar Jul 08 '20 23:07 cowtowncoder

Merged, will be in 2.12.0. Thank you @jobosk for contributing this!

cowtowncoder avatar Jul 11 '20 17:07 cowtowncoder