use of com.fasterxml.jackson.databind.jsontype.TypeDeserializer in project jackson-databind by FasterXML.
the class DeserializationContext method findRootValueDeserializer.
/**
* Method for finding a deserializer for root-level value.
*/
@SuppressWarnings("unchecked")
public final JsonDeserializer<Object> findRootValueDeserializer(JavaType type) throws JsonMappingException {
JsonDeserializer<Object> deser = _cache.findValueDeserializer(this, _factory, type);
if (deser == null) {
// can this occur?
return null;
}
deser = (JsonDeserializer<Object>) handleSecondaryContextualization(deser, null, type);
TypeDeserializer typeDeser = _factory.findTypeDeserializer(_config, type);
if (typeDeser != null) {
// important: contextualize to indicate this is for root value
typeDeser = typeDeser.forProperty(null);
return new TypeWrappedDeserializer(typeDeser, deser);
}
return deser;
}
use of com.fasterxml.jackson.databind.jsontype.TypeDeserializer in project x-pipe by ctripcorp.
the class PairDeserial method deserialize.
@Override
public Pair<Object, Object> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
JsonToken t = p.getCurrentToken();
if (t != JsonToken.START_OBJECT && t != JsonToken.FIELD_NAME && t != JsonToken.END_OBJECT) {
// slightly redundant (since String was passed above), but
return _deserializeFromEmpty(p, ctxt);
}
if (t == JsonToken.START_OBJECT) {
t = p.nextToken();
}
if (t != JsonToken.FIELD_NAME) {
if (t == JsonToken.END_OBJECT) {
ctxt.reportMappingException("Can not deserialize a Map.Entry out of empty JSON Object");
return null;
}
return (Pair<Object, Object>) ctxt.handleUnexpectedToken(handledType(), p);
}
final KeyDeserializer keyDes = _keyDeserializer;
final JsonDeserializer<Object> valueDes = _valueDeserializer;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
final String keyStr = p.getCurrentName();
Object key = keyDes.deserializeKey(keyStr, ctxt);
Object value = null;
// And then the value...
t = p.nextToken();
try {
// Note: must handle null explicitly here; value deserializers won't
if (t == JsonToken.VALUE_NULL) {
value = valueDes.getNullValue(ctxt);
} else if (typeDeser == null) {
value = valueDes.deserialize(p, ctxt);
} else {
value = valueDes.deserializeWithType(p, ctxt, typeDeser);
}
} catch (Exception e) {
throw new IllegalStateException("pair value deserialize error", e);
}
// Close, but also verify that we reached the END_OBJECT
t = p.nextToken();
if (t != JsonToken.END_OBJECT) {
if (t == JsonToken.FIELD_NAME) {
// most likely
ctxt.reportMappingException("Problem binding JSON into Map.Entry: more than one entry in JSON (second field: '" + p.getCurrentName() + "')");
} else {
// how would this occur?
ctxt.reportMappingException("Problem binding JSON into Map.Entry: unexpected content after JSON Object entry: " + t);
}
return null;
}
return new Pair<>(key, value);
}
use of com.fasterxml.jackson.databind.jsontype.TypeDeserializer in project joynr by bmwcarit.
the class AbstractBounceProxyServerTest method getObjectMapper.
// ///////////////////////
// HELPERS
private ObjectMapper getObjectMapper() {
objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
// objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS,
// true);
objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName");
TypeResolverBuilder<?> joynrTypeResolverBuilder = objectMapper.getSerializationConfig().getDefaultTyper(SimpleType.construct(Object.class));
SimpleModule module = new SimpleModule("NonTypedModule", new Version(1, 0, 0, "", "", ""));
module.addSerializer(new JoynrEnumSerializer());
module.addSerializer(new JoynrListSerializer());
TypeDeserializer typeDeserializer = joynrTypeResolverBuilder.buildTypeDeserializer(objectMapper.getDeserializationConfig(), SimpleType.construct(Object.class), null);
module.addDeserializer(Object.class, new JoynrUntypedObjectDeserializer(typeDeserializer));
objectMapper.registerModule(module);
return objectMapper;
}
use of com.fasterxml.jackson.databind.jsontype.TypeDeserializer in project beam by apache.
the class PipelineOptionsFactory method computeDeserializerForMethod.
private static JsonDeserializer<Object> computeDeserializerForMethod(Method method) {
try {
BeanProperty prop = createBeanProperty(method);
AnnotatedMember annotatedMethod = prop.getMember();
DefaultDeserializationContext context = DESERIALIZATION_CONTEXT.get();
Object maybeDeserializerClass = context.getAnnotationIntrospector().findDeserializer(annotatedMethod);
JsonDeserializer<Object> jsonDeserializer = context.deserializerInstance(annotatedMethod, maybeDeserializerClass);
if (jsonDeserializer == null) {
jsonDeserializer = context.findContextualValueDeserializer(prop.getType(), prop);
}
TypeDeserializer typeDeserializer = context.getFactory().findTypeDeserializer(context.getConfig(), prop.getType());
if (typeDeserializer != null) {
jsonDeserializer = new TypeWrappedDeserializer(typeDeserializer, jsonDeserializer);
}
return jsonDeserializer;
} catch (JsonMappingException e) {
throw new RuntimeException(e);
}
}
use of com.fasterxml.jackson.databind.jsontype.TypeDeserializer in project cyclops by aol.
the class IterableXDeserializer method createContextual.
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
JsonDeserializer<?> deser = this.valueDeserializer;
TypeDeserializer typeDeser = this.typeDeserializerForValue;
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(type.getContentType(), property);
}
if (typeDeser != null) {
typeDeser = typeDeser.forProperty(property);
}
return new IterableXDeserializer(elementType, itX, typeDeser, deser, type);
}
Aggregations