Skip to content

Commit

Permalink
[#1878] Avoid overriding a user provided deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Apr 19, 2024
1 parent e5f6eb7 commit f0b5d60
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
import com.blazebit.persistence.view.metamodel.MethodAttribute;
import com.blazebit.persistence.view.metamodel.ViewMetamodel;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.deser.AbstractDeserializer;
import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
import com.fasterxml.jackson.databind.module.SimpleModule;
Expand All @@ -51,14 +53,22 @@ public EntityViewAwareObjectMapper(final EntityViewManager entityViewManager, fi

public EntityViewAwareObjectMapper(final EntityViewManager entityViewManager, final ObjectMapper objectMapper, final EntityViewIdValueAccessor entityViewIdValueAccessor) {
this.entityViewManager = entityViewManager;
SimpleModule module = new SimpleModule();
SimpleModule module = new SimpleModule("Blaze-Persistence" );

module.setDeserializerModifier(new BeanDeserializerModifier() {
@Override
public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
ManagedViewType<?> view = entityViewManager.getMetamodel().managedView(beanDesc.getBeanClass());
if (view != null) {
return new EntityViewReferenceDeserializer(entityViewManager, view, objectMapper, beanDesc.getIgnoredPropertyNames(), entityViewIdValueAccessor);
if ( deserializer instanceof AbstractDeserializer ) {
ManagedViewType<?> view = entityViewManager.getMetamodel().managedView( beanDesc.getBeanClass() );
if ( view != null ) {
return new EntityViewReferenceDeserializer(
entityViewManager,
view,
objectMapper,
beanDesc.getIgnoredPropertyNames(),
entityViewIdValueAccessor
);
}
}
return deserializer;
}
Expand Down

0 comments on commit f0b5d60

Please sign in to comment.