下面列出了com.fasterxml.jackson.databind.jsontype.TypeDeserializer#forProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
throws JsonMappingException
{
JsonDeserializer<?> deser = _valueDeserializer;
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(_fullType.getReferencedType(), property);
} else { // otherwise directly assigned, probably not contextual yet:
deser = ctxt.handleSecondaryContextualization(deser, property, _fullType.getReferencedType());
}
TypeDeserializer typeDeser = _valueTypeDeserializer;
if (typeDeser != null) {
typeDeser = typeDeser.forProperty(property);
}
// !!! 23-Oct-2016, tatu: TODO: full support for configurable ValueInstantiators?
if ((deser == _valueDeserializer) && (typeDeser == _valueTypeDeserializer)) {
return this;
}
return withResolved(typeDeser, deser);
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
JsonDeserializer<?> valueDeser = _elementDeserializer;
Boolean unwrapSingle = findFormatFeature(ctxt, property, _containerType.getRawClass(),
JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
// May have a content converter
valueDeser = findConvertingContentDeserializer(ctxt, property, valueDeser);
final JavaType vt = _containerType.getContentType();
if (valueDeser == null) {
valueDeser = ctxt.findContextualValueDeserializer(vt, property);
} else { // if directly assigned, probably not yet contextual, so:
valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
}
TypeDeserializer elemTypeDeser = _elementTypeDeserializer;
if (elemTypeDeser != null) {
elemTypeDeser = elemTypeDeser.forProperty(property);
}
NullValueProvider nuller = findContentNullProvider(ctxt, property, valueDeser);
return withResolved(elemTypeDeser, valueDeser, nuller, unwrapSingle);
}
/**
* Method called to finalize setup of this deserializer,
* when it is known for which property deserializer is needed for.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException
{
// note: instead of finding key deserializer, with enums we actually
// work with regular deserializers (less code duplication; but not
// quite as clean as it ought to be)
KeyDeserializer keyDeser = _keyDeserializer;
if (keyDeser == null) {
keyDeser = ctxt.findKeyDeserializer(_containerType.getKeyType(), property);
}
JsonDeserializer<?> valueDeser = _valueDeserializer;
final JavaType vt = _containerType.getContentType();
if (valueDeser == null) {
valueDeser = ctxt.findContextualValueDeserializer(vt, property);
} else { // if directly assigned, probably not yet contextual, so:
valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
}
TypeDeserializer vtd = _valueTypeDeserializer;
if (vtd != null) {
vtd = vtd.forProperty(property);
}
return withResolved(keyDeser, valueDeser, vtd, findContentNullProvider(ctxt, property, valueDeser));
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
// Need to create a temporary property to allow contextual deserializers:
BeanProperty.Std property = new BeanProperty.Std(TEMP_PROPERTY_NAME,
delegateType, null, delegateCreator,
PropertyMetadata.STD_OPTIONAL);
TypeDeserializer td = delegateType.getTypeHandler();
if (td == null) {
td = ctxt.getConfig().findTypeDeserializer(delegateType);
}
JsonDeserializer<Object> dd = findDeserializer(ctxt, delegateType, property);
if (td != null) {
td = td.forProperty(property);
return new TypeWrappedDeserializer(td, dd);
}
return dd;
}
/**
* 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;
}
@Override
public RefValueHandler createContextualValue(DeserializationContext ctxt, BeanProperty property)
throws JsonMappingException {
JsonDeserializer<?> deser;
if (_valueDeserializer == null) {
deser = ctxt.findContextualValueDeserializer(_valueType, property);
} else {
deser = _valueDeserializer;
}
TypeDeserializer typeDeser = _typeDeserializerForValue == null ?
ctxt.findTypeDeserializer(_valueType) : _typeDeserializerForValue;
if (typeDeser != null) {
typeDeser = typeDeser.forProperty(property);
}
//noinspection ObjectEquality
if (deser == _valueDeserializer && typeDeser == _typeDeserializerForValue) {
return this;
}
return new RefValueHandler(_valueType, deser, typeDeser);
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
throws JsonMappingException {
JsonDeserializer<?> deser = _valueDeserializer;
TypeDeserializer typeDeser = _typeDeserializerForValue;
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(_elementType, property);
}
if (typeDeser != null) {
typeDeser = typeDeser.forProperty(property);
}
if (deser == _valueDeserializer && typeDeser == _typeDeserializerForValue) {
return this;
}
return withResolved(typeDeser, deser);
}
/**
* We need to use this method to properly handle possible contextual variants of key and value
* deserializers, as well as type deserializers.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
KeyDeserializer kd = _keyDeserializer;
if (kd == null) {
kd = ctxt.findKeyDeserializer(_containerType.getKeyType(), property);
}
JsonDeserializer<?> valueDeser = _valueDeserializer;
final JavaType vt = _containerType.getContentType();
if (valueDeser == null) {
valueDeser = ctxt.findContextualValueDeserializer(vt, property);
} else { // if directly assigned, probably not yet contextual, so:
valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
}
// Type deserializer is slightly different; must be passed, but needs to become contextual:
TypeDeserializer vtd = _valueTypeDeserializer;
if (vtd != null) {
vtd = vtd.forProperty(property);
}
return _createContextual(_containerType, kd, vtd, valueDeser, creatorMethod,
findContentNullProvider(ctxt, property, valueDeser));
}
/**
* Method called to finalize setup of this deserializer,
* after deserializer itself has been registered. This
* is needed to handle recursive and transitive dependencies.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
JsonDeserializer<?> deser = _valueDeserializer;
TypeDeserializer typeDeser = _typeDeserializerForValue;
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(_containerType.getContentType(), property);
}
if (typeDeser != null) {
typeDeser = typeDeser.forProperty(property);
}
if (deser == _valueDeserializer && typeDeser == _typeDeserializerForValue) {
return this;
}
return withResolved(typeDeser, deser);
}
/**
* Method called to finalize setup of this deserializer,
* after deserializer itself has been registered. This
* is needed to handle recursive and transitive dependencies.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
KeyDeserializer keyDeser = _keyDeserializer;
JsonDeserializer<?> deser = _valueDeserializer;
TypeDeserializer typeDeser = _typeDeserializerForValue;
// Do we need any contextualization?
if ((keyDeser != null) && (deser != null) && (typeDeser == null)) { // nope
return this;
}
if (keyDeser == null) {
keyDeser = ctxt.findKeyDeserializer(_mapType.getKeyType(), property);
}
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(_mapType.getContentType(), property);
}
if (typeDeser != null) {
typeDeser = typeDeser.forProperty(property);
}
return withResolved(keyDeser, typeDeser, deser);
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
throws JsonMappingException {
JsonDeserializer<?> deser = _valueDeserializer;
TypeDeserializer typeDeser = _typeDeserializerForValue;
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(_elementType, property);
}
if (typeDeser != null) {
typeDeser = typeDeser.forProperty(property);
}
if (deser == _valueDeserializer && typeDeser == _typeDeserializerForValue) {
return this;
}
return withResolved(typeDeser, deser);
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
JsonDeserializer<?> deser = valueDeserializer;
TypeDeserializer typeDeser = valueTypeDeserializer;
JavaType refType = valueType;
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(refType, property);
} else { // otherwise directly assigned, probably not contextual yet:
deser = ctxt.handleSecondaryContextualization(deser, property, refType);
}
if (typeDeser != null) {
typeDeser = typeDeser.forProperty(property);
}
return new LazyDeserializer(this, typeDeser, deser);
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
JsonDeserializer<?> deser = valueDeserializer;
TypeDeserializer typeDeser = valueTypeDeserializer;
JavaType refType = valueType;
if (deser == null) {
deser = ctxt.findContextualValueDeserializer(refType, property);
} else { // otherwise directly assigned, probably not contextual yet:
deser = ctxt.handleSecondaryContextualization(deser, property, refType);
}
if (typeDeser != null) {
typeDeser = typeDeser.forProperty(property);
}
return withResolved(refType, typeDeser, deser);
}
/**
* Method called to finalize setup of this deserializer,
* when it is known for which property deserializer is needed for.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
KeyDeserializer kd = _keyDeserializer;
if (kd == null) {
kd = ctxt.findKeyDeserializer(_containerType.containedType(0), property);
} else {
if (kd instanceof ContextualKeyDeserializer) {
kd = ((ContextualKeyDeserializer) kd).createContextual(ctxt, property);
}
}
JsonDeserializer<?> vd = _valueDeserializer;
vd = findConvertingContentDeserializer(ctxt, property, vd);
JavaType contentType = _containerType.containedType(1);
if (vd == null) {
vd = ctxt.findContextualValueDeserializer(contentType, property);
} else { // if directly assigned, probably not yet contextual, so:
vd = ctxt.handleSecondaryContextualization(vd, property, contentType);
}
TypeDeserializer vtd = _valueTypeDeserializer;
if (vtd != null) {
vtd = vtd.forProperty(property);
}
return withResolved(kd, vtd, vd);
}
protected SettableBeanProperty(PropertyName propName, JavaType type, PropertyName wrapper,
TypeDeserializer typeDeser, Annotations contextAnnotations,
PropertyMetadata metadata)
{
super(metadata);
// 09-Jan-2009, tatu: Intern()ing makes sense since Jackson parsed
// field names are (usually) interned too, hence lookups will be faster.
// 23-Oct-2009, tatu: should this be disabled wrt [JACKSON-180]?
// Probably need not, given that namespace of field/method names
// is not unbounded, unlike potential JSON names.
if (propName == null) {
_propName = PropertyName.NO_NAME;
} else {
_propName = propName.internSimpleName();
}
_type = type;
_wrapperName = wrapper;
_contextAnnotations = contextAnnotations;
_viewMatcher = null;
// 30-Jan-2012, tatu: Important: contextualize TypeDeserializer now...
if (typeDeser != null) {
typeDeser = typeDeser.forProperty(this);
}
_valueTypeDeserializer = typeDeser;
_valueDeserializer = MISSING_VALUE_DESERIALIZER;
_nullProvider = MISSING_VALUE_DESERIALIZER;
}
/**
* Method called to finalize setup of this deserializer,
* after deserializer itself has been registered. This
* is needed to handle recursive and transitive dependencies.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
Boolean unwrapSingle = findFormatFeature(ctxt, property, Collection.class,
JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
JsonDeserializer<?> valueDeser = _valueDeserializer;
TypeDeserializer valueTypeDeser = _valueTypeDeserializer;
if (valueDeser == null) {
valueDeser = ctxt.findContextualValueDeserializer(_containerType.getContentType(), property);
}
if (valueTypeDeser != null) {
valueTypeDeser = valueTypeDeser.forProperty(property);
}
NullValueProvider nuller = findContentNullProvider(ctxt, property, valueDeser);
if ( (unwrapSingle != _unwrapSingle)
|| (nuller != _nullProvider)
|| (valueDeser != _valueDeserializer)
|| (valueTypeDeser != _valueTypeDeserializer)) {
return withResolved(valueDeser, valueTypeDeser, nuller, unwrapSingle);
}
return this;
}
@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);
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
JsonDeserializer<?> elementDeser = elementDeserializer;
TypeDeserializer elementTypeDeser = elementTypeDeserializer;
if (elementDeser == null) {
elementDeser = ctxt.findContextualValueDeserializer(elementType, property);
} else {
elementDeser = ctxt.handleSecondaryContextualization(elementDeser, property, elementType);
}
if (elementTypeDeser != null) {
elementTypeDeser = elementTypeDeser.forProperty(property);
}
return createDeserializer(elementTypeDeser, elementDeser);
}
/**
* Method called to finalize setup of this deserializer,
* when it is known for which property deserializer is needed for.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
KeyDeserializer keyDeser = _keyDeserializer;
if (keyDeser == null) {
keyDeser = ctxt.findKeyDeserializer(_containerType.getKeyType(), property);
} else {
if (keyDeser instanceof ContextualKeyDeserializer) {
keyDeser = ((ContextualKeyDeserializer) keyDeser).createContextual(ctxt, property);
}
}
JsonDeserializer<?> valueDeser = _valueDeserializer;
// [databind#125]: May have a content converter
if (property != null) {
valueDeser = findConvertingContentDeserializer(ctxt, property, valueDeser);
}
final JavaType vt = _containerType.getContentType();
if (valueDeser == null) {
valueDeser = ctxt.findContextualValueDeserializer(vt, property);
} else { // if directly assigned, probably not yet contextual, so:
valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
}
TypeDeserializer vtd = _valueTypeDeserializer;
if (vtd != null) {
vtd = vtd.forProperty(property);
}
Set<String> ignored = _ignorableProperties;
AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
if (_neitherNull(intr, property)) {
AnnotatedMember member = property.getMember();
if (member != null) {
JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(member);
if (ignorals != null) {
Set<String> ignoresToAdd = ignorals.findIgnoredForDeserialization();
if (!ignoresToAdd.isEmpty()) {
ignored = (ignored == null) ? new HashSet<String>() : new HashSet<String>(ignored);
for (String str : ignoresToAdd) {
ignored.add(str);
}
}
}
}
}
return withResolved(keyDeser, vtd, valueDeser,
findContentNullProvider(ctxt, property, valueDeser), ignored);
}
/**
* Method called to finalize setup of this deserializer,
* after deserializer itself has been registered. This
* is needed to handle recursive and transitive dependencies.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
KeyDeserializer keyDeser = _keyDeserializer;
JsonDeserializer<?> valueDeser = _valueDeserializer;
TypeDeserializer valueTypeDeser = _valueTypeDeserializer;
// First: fetch and/or contextualize deserializers (key, value, value type)
if (keyDeser == null) {
keyDeser = ctxt.findKeyDeserializer(_containerType.getKeyType(), property);
} else {
if (keyDeser instanceof ContextualKeyDeserializer) {
keyDeser = ((ContextualKeyDeserializer) keyDeser).createContextual(ctxt, property);
}
}
final JavaType vt = _containerType.getContentType();
if (valueDeser == null) {
valueDeser = ctxt.findContextualValueDeserializer(vt, property);
} else {
valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
}
if (valueTypeDeser != null) {
valueTypeDeser = valueTypeDeser.forProperty(property);
}
// Then other handlers
NullValueProvider nuller = findContentNullProvider(ctxt, property, valueDeser);
// !!! 08-Aug-2019, tatu: TODO: null skipping? Ignored properties?
if ((_keyDeserializer == keyDeser) && (_valueDeserializer == valueDeser)
&& (_valueTypeDeserializer == valueTypeDeser)
&& (_nullProvider == nuller)
) {
return this;
}
return withResolved(keyDeser, valueDeser, valueTypeDeser, nuller);
}