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 Project: vividus Author: vividus-framework File: ObjectMapperFactory.java License: 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 #2
Source Project: Flink-CEPplus Author: ljygz File: BeanDeserializerModifierForIgnorables.java License: 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 #3
Source Project: flink Author: flink-tpc-ds File: BeanDeserializerModifierForIgnorables.java License: 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 #4
Source Project: client-sdk-java Author: PlatONnetwork File: ObjectMapperFactory.java License: 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 #5
Source Project: etherscan-explorer Author: bing-chou File: ObjectMapperFactory.java License: 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 #6
Source Project: webauthn4j Author: webauthn4j File: RegistrationExtensionClientInputDeserializer.java License: 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 #7
Source Project: webauthn4j Author: webauthn4j File: ExtensionAuthenticatorOutputDeserializer.java License: 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 #8
Source Project: webauthn4j Author: webauthn4j File: ExtensionClientInputDeserializer.java License: 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 #9
Source Project: jackson-modules-base Author: FasterXML File: TestSimpleMaterializedInterfaces.java License: 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 #10
Source Project: botbuilder-java Author: microsoft File: FlatteningDeserializer.java License: 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 #11
Source Project: lams Author: lamsfoundation File: BasicClassIntrospector.java License: 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 #12
Source Project: lams Author: lamsfoundation File: BasicClassIntrospector.java License: 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 #13
Source Project: jackson-modules-base Author: FasterXML File: AbstractTypeMaterializer.java License: 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 #14
Source Project: autorest-clientruntime-for-java Author: Azure File: FlatteningDeserializer.java License: 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 #15
Source Project: autorest-clientruntime-for-java Author: Azure File: AdditionalPropertiesDeserializer.java License: 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 #16
Source Project: Flink-CEPplus Author: ljygz File: BeanDeserializerModifierForIgnorables.java License: Apache License 2.0 | 5 votes |
@Override public BeanDeserializerBuilder updateBuilder( DeserializationConfig config, BeanDescription beanDesc, BeanDeserializerBuilder builder) { if (!type.equals(beanDesc.getBeanClass())) { return builder; } for (String ignorable : ignorables) { builder.addIgnorable(ignorable); } return builder; }
Example #17
Source Project: flink Author: flink-tpc-ds File: BeanDeserializerModifierForIgnorables.java License: Apache License 2.0 | 5 votes |
@Override public BeanDeserializerBuilder updateBuilder( DeserializationConfig config, BeanDescription beanDesc, BeanDeserializerBuilder builder) { if (!type.equals(beanDesc.getBeanClass())) { return builder; } for (String ignorable : ignorables) { builder.addIgnorable(ignorable); } return builder; }
Example #18
Source Project: n2o-framework Author: i-novus-llc File: RestEngineTimeModule.java License: Apache License 2.0 | 5 votes |
public RestEngineTimeModule(String[] patterns) { this(); setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (beanDesc.getBeanClass() == String.class) { CustomDateDeserializer dateDeserializer = new CustomDateDeserializer(deserializer); dateDeserializer.setPatterns(patterns); return dateDeserializer; } return deserializer; } }); }
Example #19
Source Project: n2o-framework Author: i-novus-llc File: RestEngineTimeModule.java License: Apache License 2.0 | 5 votes |
public RestEngineTimeModule(String[] patterns, String[] exclusionKeys) { this(); setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (beanDesc.getBeanClass() == String.class) { CustomDateDeserializer dateDeserializer = new CustomDateDeserializer(deserializer); dateDeserializer.setPatterns(patterns); dateDeserializer.setExclusions(exclusionKeys); return dateDeserializer; } return deserializer; } }); }
Example #20
Source Project: Sparkplug Author: Cirrus-Link File: DeserializerModifier.java License: Eclipse Public License 1.0 | 5 votes |
@Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (Metric.class.equals(beanDesc.getBeanClass())) { return new MetricDeserializer(deserializer); } return super.modifyDeserializer(config, beanDesc, deserializer); }
Example #21
Source Project: chrome-devtools-java-client Author: kklisura File: BaseSubTypeJsonDeserializer.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public T deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException { ObjectCodec objectCodec = jsonParser.getCodec(); ObjectNode objectNode = objectCodec.readTree(jsonParser); String typeValue = null; JsonNode type = objectNode.get(TYPE_PROPERTY); if (type != null) { typeValue = type.asText(); if (STRING_PROPERTY_VALUE.equals(typeValue)) { if (objectNode.get(ENUM_PROPERTY) != null) { typeValue = "enum"; } } } else { if (objectNode.get(REF_PROPERTY) != null) { typeValue = "ref"; } } if (typeValue == null) { throw new JsonParseException(jsonParser, "Unknown object type."); } DeserializationConfig config = context.getConfig(); AnnotatedClass annotatedClass = AnnotatedClassResolver.resolveWithoutSuperTypes(config, handledType()); List<NamedType> subtypes = config.getAnnotationIntrospector().findSubtypes(annotatedClass); for (NamedType namedType : subtypes) { if (typeValue.equals(namedType.getName())) { return (T) objectCodec.treeToValue(objectNode, namedType.getType()); } } throw new JsonParseException(jsonParser, "Unknown object type " + typeValue + "."); }
Example #22
Source Project: jackson-modules-base Author: FasterXML File: TestSimpleMaterializedInterfaces.java License: Apache License 2.0 | 5 votes |
private Class<?> _materializeRawType(AbstractTypeMaterializer mat, DeserializationConfig config, Class<?> cls) { JavaType type = config.constructType(cls); return mat.materializeRawType(config, AnnotatedClassResolver.resolve(config, type, config)); }
Example #23
Source Project: web3sdk Author: FISCO-BCOS File: ObjectMapperFactory.java License: 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; }
Example #24
Source Project: lams Author: lamsfoundation File: SimpleValueInstantiators.java License: 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 #25
Source Project: lams Author: lamsfoundation File: SimpleAbstractTypeResolver.java License: GNU General Public License v2.0 | 5 votes |
@Override public JavaType findTypeMapping(DeserializationConfig config, JavaType type) { // this is the main mapping base, so let's Class<?> src = type.getRawClass(); Class<?> dst = _mappings.get(new ClassKey(src)); if (dst == null) { return null; } // 09-Aug-2015, tatu: Instead of direct call via JavaType, better use TypeFactory return config.getTypeFactory().constructSpecializedType(type, dst); }
Example #26
Source Project: lams Author: lamsfoundation File: BasicClassIntrospector.java License: 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 #27
Source Project: lams Author: lamsfoundation File: JsonLocationInstantiator.java License: 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 #28
Source Project: quilt Author: hyperledger File: InterledgerDeserializers.java License: 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 #29
Source Project: curiostack Author: curioswitch File: ProtobufModule.java License: 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 #30
Source Project: JglTF Author: javagl File: JacksonUtils.java License: 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; } }; }