com.fasterxml.jackson.databind.DeserializationConfig Java Examples
The following examples show how to use
com.fasterxml.jackson.databind.DeserializationConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasicClassIntrospector.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public BasicBeanDescription forDeserialization(DeserializationConfig cfg, JavaType type, MixInResolver r) { // minor optimization: for some JDK types do minimal introspection BasicBeanDescription desc = _findStdTypeDesc(type); if (desc == null) { // As per [Databind#550], skip full introspection for some of standard // structured types as well desc = _findStdJdkCollectionDesc(cfg, type); if (desc == null) { desc = BasicBeanDescription.forDeserialization(collectProperties(cfg, type, r, false, "set")); } // Also: this is a superset of "forClassAnnotations", so may optimize by optional add: _cachedFCA.putIfAbsent(type, desc); } return desc; }
Example #2
Source File: TestSimpleMaterializedInterfaces.java From jackson-modules-base with Apache License 2.0 | 6 votes |
/** * First test verifies that bean builder works as expected */ public void testLowLevelMaterializer() throws Exception { AbstractTypeMaterializer mat = new AbstractTypeMaterializer(); DeserializationConfig config = new ObjectMapper().deserializationConfig(); Class<?> impl = _materializeRawType(mat, config, Bean.class); assertNotNull(impl); assertTrue(Bean.class.isAssignableFrom(impl)); // also, let's instantiate to make sure: Object ob = ClassUtil.createInstance(impl, false); // and just for good measure do actual cast Bean bean = (Bean) ob; // call something to ensure generation worked... assertNull(bean.getA()); // Also: let's verify that we can handle dup calls: Class<?> impl2 = _materializeRawType(mat, config, Bean.class); assertNotNull(impl2); assertSame(impl, impl2); }
Example #3
Source File: ExtensionClientInputDeserializer.java From webauthn4j with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public ExtensionClientInput<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { String name = p.getParsingContext().getCurrentName(); if (name == null) { name = p.getParsingContext().getParent().getCurrentName(); } DeserializationConfig config = ctxt.getConfig(); AnnotatedClass annotatedClass = AnnotatedClassResolver.resolveWithoutSuperTypes(config, ExtensionClientInput.class); Collection<NamedType> namedTypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(config, annotatedClass); for (NamedType namedType : namedTypes) { if (Objects.equals(namedType.getName(), name)) { return (ExtensionClientInput<?>) ctxt.readValue(p, namedType.getType()); } } logger.warn("Unknown extension '{}' is contained.", name); return ctxt.readValue(p, UnknownExtensionClientInput.class); }
Example #4
Source File: ExtensionAuthenticatorOutputDeserializer.java From webauthn4j with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public ExtensionAuthenticatorOutput<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { String name = p.getParsingContext().getCurrentName(); if (name == null) { name = p.getParsingContext().getParent().getCurrentName(); } DeserializationConfig config = ctxt.getConfig(); AnnotatedClass annotatedClass = AnnotatedClassResolver.resolveWithoutSuperTypes(config, ExtensionAuthenticatorOutput.class); Collection<NamedType> namedTypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(config, annotatedClass); for (NamedType namedType : namedTypes) { if (Objects.equals(namedType.getName(), name)) { return (ExtensionAuthenticatorOutput<?>) ctxt.readValue(p, namedType.getType()); } } logger.warn("Unknown extension '{}' is contained.", name); return ctxt.readValue(p, UnknownExtensionAuthenticatorOutput.class); }
Example #5
Source File: RegistrationExtensionClientInputDeserializer.java From webauthn4j with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public RegistrationExtensionClientInput<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { String name = p.getParsingContext().getCurrentName(); if (name == null) { name = p.getParsingContext().getParent().getCurrentName(); } DeserializationConfig config = ctxt.getConfig(); AnnotatedClass annotatedClass = AnnotatedClassResolver.resolveWithoutSuperTypes(config, RegistrationExtensionClientInput.class); Collection<NamedType> namedTypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(config, annotatedClass); for (NamedType namedType : namedTypes) { if (Objects.equals(namedType.getName(), name)) { return (RegistrationExtensionClientInput<?>) ctxt.readValue(p, namedType.getType()); } } logger.warn("Unknown extension '{}' is contained.", name); return ctxt.readValue(p, UnknownExtensionClientInput.class); }
Example #6
Source File: AdditionalPropertiesDeserializer.java From autorest-clientruntime-for-java with MIT License | 6 votes |
/** * Gets a module wrapping this serializer as an adapter for the Jackson * ObjectMapper. * * @param mapper the object mapper for default deserializations * @return a simple module to be plugged onto Jackson ObjectMapper. */ public static SimpleModule getModule(final ObjectMapper mapper) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { for (Class<?> c : TypeToken.of(beanDesc.getBeanClass()).getTypes().classes().rawTypes()) { Field[] fields = c.getDeclaredFields(); for (Field field : fields) { if ("additionalProperties".equalsIgnoreCase(field.getName())) { JsonProperty property = field.getAnnotation(JsonProperty.class); if (property != null && property.value().isEmpty()) { return new AdditionalPropertiesDeserializer(beanDesc.getBeanClass(), deserializer, mapper); } } } } return deserializer; } }); return module; }
Example #7
Source File: AbstractTypeMaterializer.java From jackson-modules-base with Apache License 2.0 | 6 votes |
/** * Entry-point for {@link AbstractTypeResolver} that Jackson calls to materialize * an abstract type. */ @Override public JavaType resolveAbstractType(DeserializationConfig config, BeanDescription beanDesc) { final JavaType type = beanDesc.getType(); if (!_suitableType(type)) { return null; } // might want to skip proxies, local types too... but let them be for now: //if (intr.findTypeResolver(beanDesc.getClassInfo(), type) == null) { Class<?> materializedType; if (type.hasGenericTypes()) { materializedType = materializeGenericType(config, type); } else { materializedType = materializeRawType(config, beanDesc.getClassInfo()); } return config.constructType(materializedType); }
Example #8
Source File: FlatteningDeserializer.java From botbuilder-java with MIT License | 6 votes |
/** * Gets a module wrapping this serializer as an adapter for the Jackson * ObjectMapper. * * @param mapper the object mapper for default deserializations * @return a simple module to be plugged onto Jackson ObjectMapper. */ public static SimpleModule getModule(final ObjectMapper mapper) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (BeanDeserializer.class.isAssignableFrom(deserializer.getClass())) { // Apply flattening deserializer on all POJO types. return new FlatteningDeserializer(beanDesc.getBeanClass(), deserializer, mapper); } else { return deserializer; } } }); return module; }
Example #9
Source File: ObjectMapperFactory.java From etherscan-explorer with GNU General Public License v3.0 | 6 votes |
private static ObjectMapper configureObjectMapper( ObjectMapper objectMapper, boolean shouldIncludeRawResponses) { if (shouldIncludeRawResponses) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) { return new RawResponseDeserializer(deserializer); } return deserializer; } }); objectMapper.registerModule(module); } objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; }
Example #10
Source File: ObjectMapperFactory.java From client-sdk-java with Apache License 2.0 | 6 votes |
private static ObjectMapper configureObjectMapper( ObjectMapper objectMapper, boolean shouldIncludeRawResponses) { if (shouldIncludeRawResponses) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) { return new RawResponseDeserializer(deserializer); } return deserializer; } }); objectMapper.registerModule(module); } objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; }
Example #11
Source File: ObjectMapperFactory.java From vividus with Apache License 2.0 | 6 votes |
public static ObjectMapper createWithCaseInsensitiveEnumDeserializer() { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<Enum<?>> modifyEnumDeserializer(DeserializationConfig config, final JavaType type, BeanDescription beanDescription, final JsonDeserializer<?> deserializer) { return new JsonDeserializer<>() { @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Enum<?> deserialize(JsonParser parser, DeserializationContext context) throws IOException { return Enum.valueOf((Class<? extends Enum>) type.getRawClass(), parser.getValueAsString().toUpperCase()); } }; } }); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(module); return objectMapper; }
Example #12
Source File: FlatteningDeserializer.java From autorest-clientruntime-for-java with MIT License | 6 votes |
/** * Gets a module wrapping this serializer as an adapter for the Jackson * ObjectMapper. * * @param mapper the object mapper for default deserializations * @return a simple module to be plugged onto Jackson ObjectMapper. */ public static SimpleModule getModule(final ObjectMapper mapper) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (BeanDeserializer.class.isAssignableFrom(deserializer.getClass())) { // Apply flattening deserializer on all POJO types. return new FlatteningDeserializer(beanDesc.getBeanClass(), deserializer, mapper); } else { return deserializer; } } }); return module; }
Example #13
Source File: BeanDeserializerModifierForIgnorables.java From flink with Apache License 2.0 | 6 votes |
@Override public List<BeanPropertyDefinition> updateProperties( DeserializationConfig config, BeanDescription beanDesc, List<BeanPropertyDefinition> propDefs) { if (!type.equals(beanDesc.getBeanClass())) { return propDefs; } List<BeanPropertyDefinition> newPropDefs = new ArrayList<>(); for (BeanPropertyDefinition propDef : propDefs) { if (!ignorables.contains(propDef.getName())) { newPropDefs.add(propDef); } } return newPropDefs; }
Example #14
Source File: BeanDeserializerModifierForIgnorables.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public List<BeanPropertyDefinition> updateProperties( DeserializationConfig config, BeanDescription beanDesc, List<BeanPropertyDefinition> propDefs) { if (!type.equals(beanDesc.getBeanClass())) { return propDefs; } List<BeanPropertyDefinition> newPropDefs = new ArrayList<>(); for (BeanPropertyDefinition propDef : propDefs) { if (!ignorables.contains(propDef.getName())) { newPropDefs.add(propDef); } } return newPropDefs; }
Example #15
Source File: BasicClassIntrospector.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public BasicBeanDescription forCreation(DeserializationConfig cfg, JavaType type, MixInResolver r) { BasicBeanDescription desc = _findStdTypeDesc(type); if (desc == null) { // As per [Databind#550], skip full introspection for some of standard // structured types as well desc = _findStdJdkCollectionDesc(cfg, type); if (desc == null) { desc = BasicBeanDescription.forDeserialization( collectProperties(cfg, type, r, false, "set")); } } // should this be cached for FCA? return desc; }
Example #16
Source File: ProtobufModule.java From curiostack with MIT License | 5 votes |
@Override @Nullable public JsonDeserializer<?> findBeanDeserializer( JavaType type, DeserializationConfig config, BeanDescription beanDesc) { if (Message.class.isAssignableFrom(type.getRawClass())) { return new MessageDeserializer(type.getRawClass()); } return null; }
Example #17
Source File: InterledgerDeserializers.java From quilt with Apache License 2.0 | 5 votes |
@Override public JsonDeserializer<?> findBeanDeserializer( JavaType type, DeserializationConfig config, BeanDescription beanDesc ) { if (type.hasRawClass(InterledgerAddress.class)) { return new InterledgerAddressDeserializer(); } if (type.hasRawClass(InterledgerAddressPrefix.class)) { return new InterledgerAddressPrefixDeserializer(); } if (type.hasRawClass(InterledgerCondition.class)) { return new ConditionDeserializer(cryptoConditionEncoding); } if (type.hasRawClass(InterledgerFulfillment.class)) { return new FulfillmentDeserializer(cryptoConditionEncoding); } if (type.hasRawClass(SharedSecret.class)) { return new SharedSecretDeserializer(); } if (type.hasRawClass(LinkId.class)) { return new LinkIdDeserializer(); } if (type.hasRawClass(LinkType.class)) { return new LinkTypeDeserializer(); } return null; }
Example #18
Source File: TestSimpleMaterializedInterfaces.java From jackson-modules-base with Apache License 2.0 | 5 votes |
public void testLowLevelMaterializerFailOnIncompatible() throws Exception { AbstractTypeMaterializer mat = new AbstractTypeMaterializer(); DeserializationConfig config = new ObjectMapper().deserializationConfig(); try { _materializeRawType(mat, config, InvalidBean.class); fail("Expected exception for incompatible property types"); } catch (IllegalArgumentException e) { verifyException(e, "incompatible types"); } }
Example #19
Source File: SimpleValueInstantiators.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public ValueInstantiator findValueInstantiator(DeserializationConfig config, BeanDescription beanDesc, ValueInstantiator defaultInstantiator) { ValueInstantiator inst = _classMappings.get(new ClassKey(beanDesc.getBeanClass())); return (inst == null) ? defaultInstantiator : inst; }
Example #20
Source File: CompositeDeserializers.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Override public JsonDeserializer<?> findCollectionLikeDeserializer(CollectionLikeType type, DeserializationConfig config, BeanDescription beanDesc, TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer) throws JsonMappingException { for (Deserializers deserializers : deserializersList) { JsonDeserializer<?> deserializer = deserializers.findCollectionLikeDeserializer(type, config, beanDesc, elementTypeDeserializer, elementDeserializer); if (deserializer != null) { return deserializer; } } return null; }
Example #21
Source File: CompositeDeserializers.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Override public JsonDeserializer<?> findArrayDeserializer(ArrayType type, DeserializationConfig config, BeanDescription beanDesc, TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer) throws JsonMappingException { for (Deserializers deserializers : deserializersList) { JsonDeserializer<?> deserializer = deserializers.findArrayDeserializer(type, config, beanDesc, elementTypeDeserializer, elementDeserializer); if (deserializer != null) { return deserializer; } } return null; }
Example #22
Source File: CompositeDeserializers.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Override public JsonDeserializer<?> findBeanDeserializer(JavaType type, DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException { for (Deserializers deserializers : deserializersList) { JsonDeserializer<?> deserializer = deserializers.findBeanDeserializer(type, config, beanDesc); if (deserializer != null) { return deserializer; } } return null; }
Example #23
Source File: CompositeDeserializers.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Override public JsonDeserializer<?> findEnumDeserializer(Class<?> type, DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException { for (Deserializers deserializers : deserializersList) { JsonDeserializer<?> deserializer = deserializers.findEnumDeserializer(type, config, beanDesc); if (deserializer != null) { return deserializer; } } return null; }
Example #24
Source File: CompositeDeserializers.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Override public JsonDeserializer<?> findTreeNodeDeserializer(Class<? extends JsonNode> nodeType, DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException { for (Deserializers deserializers : deserializersList) { JsonDeserializer<?> deserializer = deserializers.findTreeNodeDeserializer(nodeType, config, beanDesc); if (deserializer != null) { return deserializer; } } return null; }
Example #25
Source File: CompositeDeserializers.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Override public JsonDeserializer<?> findReferenceDeserializer(ReferenceType refType, DeserializationConfig config, BeanDescription beanDesc, TypeDeserializer contentTypeDeserializer, JsonDeserializer<?> contentDeserializer) throws JsonMappingException { for (Deserializers deserializers : deserializersList) { JsonDeserializer<?> deserializer = deserializers.findReferenceDeserializer(refType, config, beanDesc, contentTypeDeserializer, contentDeserializer); if (deserializer != null) { return deserializer; } } return null; }
Example #26
Source File: JacksonUtils.java From JglTF with MIT License | 5 votes |
/** * Creates a BeanDeserializerModifier that replaces the * SettableBeanProperties in the BeanDeserializerBuilder with * ErrorReportingSettableBeanProperty instances that forward * information about errors when setting bean properties to the * given consumer. (Don't ask ... ) * * @param jsonErrorConsumer The consumer for {@link JsonError}s. * If this is <code>null</code>, then no errors will be reported. * @return The modifier */ private static BeanDeserializerModifier createErrorHandlingBeanDeserializerModifier( Consumer<? super JsonError> jsonErrorConsumer) { return new BeanDeserializerModifier() { @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; } }; }
Example #27
Source File: CompositeDeserializers.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Override public JsonDeserializer<?> findMapLikeDeserializer(MapLikeType type, DeserializationConfig config, BeanDescription beanDesc, KeyDeserializer keyDeserializer, TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer) throws JsonMappingException { for (Deserializers deserializers : deserializersList) { JsonDeserializer<?> deserializer = deserializers.findMapLikeDeserializer(type, config, beanDesc, keyDeserializer, elementTypeDeserializer, elementDeserializer); if (deserializer != null) { return deserializer; } } return null; }
Example #28
Source File: BasicClassIntrospector.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public BasicBeanDescription forDeserializationWithBuilder(DeserializationConfig cfg, JavaType type, MixInResolver r) { // no std JDK types with Builders, so: BasicBeanDescription desc = BasicBeanDescription.forDeserialization(collectPropertiesWithBuilder(cfg, type, r, false)); // this is still a superset of "forClassAnnotations", so may optimize by optional add: _cachedFCA.putIfAbsent(type, desc); return desc; }
Example #29
Source File: JsonLocationInstantiator.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public SettableBeanProperty[] getFromObjectArguments(DeserializationConfig config) { JavaType intType = config.constructType(Integer.TYPE); JavaType longType = config.constructType(Long.TYPE); return new SettableBeanProperty[] { creatorProp("sourceRef", config.constructType(Object.class), 0), creatorProp("byteOffset", longType, 1), creatorProp("charOffset", longType, 2), creatorProp("lineNr", intType, 3), creatorProp("columnNr", intType, 4) }; }
Example #30
Source File: ObjectMapperFactory.java From web3j with Apache License 2.0 | 5 votes |
private static ObjectMapper configureObjectMapper( ObjectMapper objectMapper, boolean shouldIncludeRawResponses) { if (shouldIncludeRawResponses) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier( new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer( DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) { return new RawResponseDeserializer(deserializer); } return deserializer; } }); objectMapper.registerModule(module); } objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; }