@Override public BeanDeserializerBuilder updateBuilder(DeserializationConfig config, BasicBeanDescription beanDesc, BeanDeserializerBuilder builder) { Iterator<SettableBeanProperty> beanPropertyIterator = builder.getProperties(); while (beanPropertyIterator.hasNext()) { SettableBeanProperty settableBeanProperty = beanPropertyIterator.next();
@Override public BeanDeserializerBuilder updateBuilder(DeserializationConfig config, BeanDescription beanDesc, BeanDeserializerBuilder builder) { Iterator<SettableBeanProperty> properties = builder.getProperties(); entities.getPersistentEntity(beanDesc.getBeanClass()).ifPresent(entity -> { while (properties.hasNext()) { SettableBeanProperty property = properties.next(); PersistentProperty<?> persistentProperty = entity.getPersistentProperty(property.getName()); if (persistentProperty == null) { continue; } if (associationLinks.isLookupType(persistentProperty)) { RepositoryInvokingDeserializer repositoryInvokingDeserializer = new RepositoryInvokingDeserializer(factory, persistentProperty); JsonDeserializer<?> deserializer = wrapIfCollection(persistentProperty, repositoryInvokingDeserializer, config); builder.addOrReplaceProperty(property.withValueDeserializer(deserializer), false); continue; } if (!associationLinks.isLinkableAssociation(persistentProperty)) { continue; } UriStringDeserializer uriStringDeserializer = new UriStringDeserializer(persistentProperty, converter); JsonDeserializer<?> deserializer = wrapIfCollection(persistentProperty, uriStringDeserializer, config); builder.addOrReplaceProperty(property.withValueDeserializer(deserializer), false); } }); return builder; }
@Override public BeanDeserializerBuilder updateBuilder( DeserializationConfig config, BeanDescription beanDesc, BeanDeserializerBuilder builder) { Iterator<SettableBeanProperty> propertiesIterator = builder.getProperties(); while (propertiesIterator.hasNext()) { SettableBeanProperty property = propertiesIterator.next(); SettableBeanProperty wrappedProperty = new ErrorReportingSettableBeanProperty( property, jsonErrorConsumer); builder.addOrReplaceProperty(wrappedProperty, true); } return builder; } };
@Override public BeanDeserializerBuilder updateBuilder(DeserializationConfig config, BeanDescription beanDesc, BeanDeserializerBuilder builder) { Iterator<SettableBeanProperty> beanPropertyIterator = builder.getProperties(); while (beanPropertyIterator.hasNext()) { SettableBeanProperty settableBeanProperty = beanPropertyIterator.next(); Encrypted encrypted = settableBeanProperty.getAnnotation(Encrypted.class); if (encrypted == null) continue; String source = encrypted.source(); EncryptionService service = sourceMap.get(source); if (service == null) { throw new IllegalArgumentException(String.format( "No encryption key source defined for %s.", source)); } JsonDeserializer<Object> current = settableBeanProperty.getValueDeserializer(); builder.addOrReplaceProperty(settableBeanProperty .withValueDeserializer(new EncryptedJsonDeserializer(service, encrypted, current)), true); } return builder; }
protected BuilderAndPropertyMap constructBeanDeserializerBuilder(JavaType type) { BeanDescription beanDesc = serializerProvider.getConfig().introspect(type); BeanDeserializerBuilder builder; CustomBeanDeserializerFactory factory = CustomBeanDeserializerFactory.instance; DeserializationContext ctxt = ((DefaultDeserializationContext) deserializationContext).copy(); try { Field field = DeserializationContext.class.getDeclaredField("_config"); field.setAccessible(true); field.set(ctxt, deserializationConfig); // copy from factory.buildBeanDeserializer() ValueInstantiator valueInstantiator = factory.findValueInstantiator(ctxt, beanDesc); builder = new BeanDeserializerBuilder(beanDesc, ctxt); builder.setValueInstantiator(valueInstantiator); factory.addBeanProps(ctxt, beanDesc, builder); factory.addObjectIdReader(ctxt, beanDesc, builder); factory.addBackReferenceProperties(ctxt, beanDesc, builder); factory.addInjectables(ctxt, beanDesc, builder); } catch (Exception e) { throw new RuntimeException("Unexpected exception", e); } List<SettableBeanProperty> properties = new ArrayList<>(); Iterator<SettableBeanProperty> propertiesIter = builder.getProperties(); while (propertiesIter.hasNext()) { properties.add(propertiesIter.next()); } BeanPropertyMap propertyMap = new BeanPropertyMap(false, properties, Collections.<String, List<PropertyName>>emptyMap()); return new BuilderAndPropertyMap(builder, propertyMap, beanDesc); }
public static class MyBeanDeserializerModifier extends BeanDeserializerModifier { @Override public BeanDeserializerBuilder updateBuilder(DeserializationConfig config, BeanDescription beanDesc, BeanDeserializerBuilder builder) { if (beanDesc.getBeanClass() != Contact.class) { return builder; } List<PropertyName> properties = new ArrayList<>(); Iterator<SettableBeanProperty> beanPropertyIterator = builder.getProperties(); Class<?> activeView = config.getActiveView(); while (beanPropertyIterator.hasNext()) { SettableBeanProperty settableBeanProperty = beanPropertyIterator.next(); if (!settableBeanProperty.visibleInView(activeView)) { properties.add(settableBeanProperty.getFullName()); } } for(PropertyName p : properties){ builder.removeProperty(p); } return builder; } }
config, collector, builder.getProperties());
@Override public BeanDeserializerBuilder updateBuilder(DeserializationConfig config, BeanDescription beanDesc, BeanDeserializerBuilder builder) { Iterator<SettableBeanProperty> properties = builder.getProperties(); entities.getPersistentEntity(beanDesc.getBeanClass()).ifPresent(entity -> { while (properties.hasNext()) { SettableBeanProperty property = properties.next(); PersistentProperty<?> persistentProperty = entity.getPersistentProperty(property.getName()); if (persistentProperty == null) { continue; } if (associationLinks.isLookupType(persistentProperty)) { RepositoryInvokingDeserializer repositoryInvokingDeserializer = new RepositoryInvokingDeserializer(factory, persistentProperty); JsonDeserializer<?> deserializer = wrapIfCollection(persistentProperty, repositoryInvokingDeserializer, config); builder.addOrReplaceProperty(property.withValueDeserializer(deserializer), false); continue; } if (!associationLinks.isLinkableAssociation(persistentProperty)) { continue; } UriStringDeserializer uriStringDeserializer = new UriStringDeserializer(persistentProperty, converter); JsonDeserializer<?> deserializer = wrapIfCollection(persistentProperty, uriStringDeserializer, config); builder.addOrReplaceProperty(property.withValueDeserializer(deserializer), false); } }); return builder; }
config, collector, builder.getProperties());