com.fasterxml.jackson.databind.ser.ContextualSerializer Java Examples

The following examples show how to use com.fasterxml.jackson.databind.ser.ContextualSerializer. 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: StdDelegatingSerializer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property)
    throws JsonMappingException
{
    JsonSerializer<?> delSer = _delegateSerializer;
    JavaType delegateType = _delegateType;

    if (delSer == null) {
        // Otherwise, need to locate serializer to delegate to. For that we need type information...
        if (delegateType == null) {
            delegateType = _converter.getOutputType(provider.getTypeFactory());
        }
        // 02-Apr-2015, tatu: For "dynamic case", where type is only specified as
        //    java.lang.Object (or missing generic), [databind#731]
        if (!delegateType.isJavaLangObject()) {
            delSer = provider.findValueSerializer(delegateType);
        }
    }
    if (delSer instanceof ContextualSerializer) {
        delSer = provider.handleSecondaryContextualization(delSer, property);
    }
    if (delSer == _delegateSerializer && delegateType == _delegateType) {
        return this;
    }
    return withDelegate(_converter, delegateType, delSer);
}
 
Example #2
Source File: TypeWrappedSerializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override // since 2.9
public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property)
    throws JsonMappingException
{
    // 13-Mar-2017, tatu: Should we call `TypeSerializer.forProperty()`?
    JsonSerializer<?> ser = _serializer;
    if (ser instanceof ContextualSerializer) {
        ser = provider.handleSecondaryContextualization(ser, property);
    }
    if (ser == _serializer) {
        return this;
    }
    return new TypeWrappedSerializer(_typeSerializer, ser);
}
 
Example #3
Source File: ObjectMapperUtil.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property)
    throws JsonMappingException {
  if (delegate instanceof ContextualSerializer) {
    return new DeepEmptyCheckingSerializer<>(
        ((ContextualSerializer) delegate).createContextual(provider, property));
  }
  return this;
}
 
Example #4
Source File: LazyJsonModule.java    From emodb with Apache License 2.0 5 votes vote down vote up
/**
 * Override to preserve the delegating behavior when a contextualized serializer is created.
 */
@Override
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property)
        throws JsonMappingException {
    if (_delegateSerializer instanceof ContextualSerializer) {
        JsonSerializer<?> contextualDelegate = ((ContextualSerializer) _delegateSerializer).createContextual(prov, property);
        // Check for different instance
        if (contextualDelegate != _delegateSerializer) {
            return new DelegatingMapSerializer(contextualDelegate);
        }
    }
    return this;
}