Prevent using NestedEntitySerializer if target serializer does not support unwrapping.

We now verify that the serializer registered for the type that's supposed to be handled by the NestedEntitySerializer actually supports unwrapping as the serialization in EntityModel (MapSuppressingUnwrappingSerializer) requires that to work properly.

Fixes #2056.
This commit is contained in:
Oliver Drotbohm
2021-10-13 11:56:43 +02:00
parent 1828a6a2a7
commit 4434d32fae
2 changed files with 53 additions and 1 deletions

View File

@@ -406,6 +406,12 @@ public class PersistentEntityJackson2Module extends SimpleModule {
return value;
}
JsonSerializer<Object> unwrappingSerializer = serializer.unwrappingSerializer(NameTransformer.NOP);
if (!unwrappingSerializer.isUnwrappingSerializer()) {
return value;
}
PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(value.getClass());
return invoker.invokeProcessorsFor(PersistentEntityResource.build(value, entity).//