Skip to content

Feat/Change: HibernateProxy in property annotated with @JsonIdentityInfo @JsonReference(alwaysId=true) #124

Open
@f-aubert

Description

@f-aubert

Hello,

I'm facing the following the challenge I have an Entity which has a Lazy parent entity which I want to always be serialised by Id. If by any chance the Parent Entity is uninitialised and proxied, then I will get null instead of the id in JSON.

Here is an example:
// jsonidentity referring to id property
Entity {
// id
Long id;
// lazy
// jsonreference alwaysId=true
Entity parent;
}

which I expected to be serialised in Json like this:
{
id: 10,
parent: 1
}

A possibility would be to use the feature SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS, but it will create an object with a property id where I only want the id as it unwrapped. So I see two solutions,

  1. making another feature "SERIALIZE_UNWRAPPED_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS, 2) handling the NULLS in either the HibernateProxySerializer.serialize Method or HibernateProxySerializer.findProxied Method to always return init.getIdentifier() when initialised instead of null.

What are your thoughts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions