Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserializing EntityViews with jackson in Springboot yields null instead of an EntityView #1878

Closed
tom-mayer opened this issue Mar 8, 2024 · 2 comments · Fixed by #1893
Closed
Assignees
Labels
component: jackson kind: bug worth: high Implementing this has a high worth
Milestone

Comments

@tom-mayer
Copy link
Contributor

Description

When deserializing an EntityView in a DTO as payload in a @RequestBody the new Blaze version deserializes null while the old version can transform the id that is set, e.g. 3000 to the respective EntityView

The difference is, when deserializing, jackson (in MethodProperty#deserializeAndSet) uses the EntityViewReferenceDeserializer in the newer case (probably as a fallback implementation) while when using the old Blaze version <EntityIdViewName>Deserializer is used.
The EntityViewReferenceDeserializer (new version) starts looking for an { idAttribute: <Id>} (com.blazebit.persistence.integration.jackson.EntityViewReferenceDeserializer#retrieveId) in a JsonNode that only contains the value of the id (e.g. 3000) and thus cannot find an id and cannot create the EntityView.

Probably in the new version the <EntityIdViewName>Deserializer is not registered with the ObjectMapper.

The payload we would send looks something like this:

{ niceEntity: 3000, ... }

With a DTO of:

@Data
....
NiceEntityDTO {
	private NiceEntityIdView niceEntity;
    ...
}

With the idView being something like this:

@EntityView(NiceEntity::class)
interface LongIdView {
    @get:IdMapping
    val id: Long?
}

In this example in the old version of Blaze, jackson would use the NiceEntityIdViewDeserializer while in the new version EntityViewReferenceDeserializer is used to deserialize the niceEntity property in NiceEntityDTO.

Expected behavior

After deserialization the DTO class should contain a NiceEntityIdView with an id of 3000.

Actual behavior

After deserialization the DTO class should contains null for the niceEntity field.

Environment

Current Version: latest master build,
Before Version: based on 191e130
JPA-Provider: Hibernate 6.4.4.Final

@EugenMayer
Copy link
Contributor

@beikov i would assume this will be a major issue with the new upcoming version, another sideeffect from #1858 IMHO

@EugenMayer
Copy link
Contributor

EugenMayer commented Apr 18, 2024

@beikov AFAICS the reason is not that our specific SpaceIdViewDeserializer is no longer registered (it is), but rather that EntityViewAwareObjectMapper#EntityViewAwareObjectMapper does no add add a new objectMapper module EntityViewReferenceDeserializer (btw we should use a proper name there like SimpleModule module = new SimpleModule("EntityViewReferenceDeserializer"); and this one is picked before ours.

in the old BP implementation, EntityViewReferenceDeserializer was not registered as a deserialization module on the objectMapper used here.

I assume, the object mapper we now pass into EntityViewAwareMappingJackson2HttpMessageConverter with

@Bean
    @Qualifier("EntityViewAwareConverter")
    @Lazy
    fun entityViewAwareMappingJackson2HttpMessageConverter(
        entityViewManager: EntityViewManager,
        entityViewIdValueAccessor: EntityViewIdValueAccessor,
        objectMapper: ObjectMapper
    ): EntityViewAwareMappingJackson2HttpMessageConverter {
        return EntityViewAwareMappingJackson2HttpMessageConverter(
            entityViewManager,
            entityViewIdValueAccessor,
            objectMapper
        )
    }

Is the objectMapper that is used for deserialization here. And this object mapper know is manipulated within EntityViewAwareObjectMapper and an additional module is added, changing the behavior.

beikov added a commit to beikov/blaze-persistence that referenced this issue Apr 19, 2024
@beikov beikov self-assigned this Apr 19, 2024
@beikov beikov added kind: bug component: jackson worth: high Implementing this has a high worth labels Apr 19, 2024
@beikov beikov added this to the 1.6.12 milestone Apr 19, 2024
beikov added a commit to beikov/blaze-persistence that referenced this issue Apr 19, 2024
beikov added a commit to beikov/blaze-persistence that referenced this issue Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: jackson kind: bug worth: high Implementing this has a high worth
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants