Java Code Examples for com.fasterxml.jackson.databind.SerializerProvider#defaultSerializeNullValue()

The following examples show how to use com.fasterxml.jackson.databind.SerializerProvider#defaultSerializeNullValue() . 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: StringMethodPropertyWriter.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
@Override
public final void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
    if (broken) {
        fallbackWriter.serializeAsField(bean, gen, prov);
        return;
    }
    String value;
    try {
        value = _propertyAccessor.stringGetter(bean, _propertyIndex);
    } catch (Throwable t) {
        _handleProblem(bean, gen, prov, t, false);
        return;
    }
    // Null (etc) handling; copied from super-class impl
    if (value == null) {
        if (_nullSerializer != null) {
            gen.writeFieldName(_fastName);
            _nullSerializer.serialize(null, gen, prov);
        } else if (!_suppressNulls) {
            gen.writeFieldName(_fastName);
            prov.defaultSerializeNullValue(gen);
        }
        return;
    }
    if (_suppressableValue != null) {
        if (MARKER_FOR_EMPTY == _suppressableValue) {
            if (value.length() == 0) {
                return;
            }
        } else if (_suppressableValue.equals(value)) {
            return;
        }
    }
    gen.writeFieldName(_fastName);
    gen.writeString(value);
}
 
Example 2
Source File: StringMethodPropertyWriter.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
@Override
public final void serializeAsElement(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
    if (broken) {
        fallbackWriter.serializeAsElement(bean, gen, prov);
        return;
    }

    String value;
    try {
        value = _propertyAccessor.stringGetter(bean, _propertyIndex);
    } catch (Throwable t) {
        _handleProblem(bean, gen, prov, t, true);
        return;
    }
    // Null (etc) handling; copied from super-class impl
    if (value == null) {
        if (_suppressNulls) {
            serializeAsPlaceholder(bean, gen, prov);
        } else {
            prov.defaultSerializeNullValue(gen);
        }
        return;
    }
    if (_suppressableValue != null) {
        if (MARKER_FOR_EMPTY == _suppressableValue) {
            if (value.length() == 0) {
                serializeAsPlaceholder(bean, gen, prov);
                return;
            }
        } else if (_suppressableValue.equals(value)) {
            serializeAsPlaceholder(bean, gen, prov);
            return;
        }
    }
    gen.writeString(value);
}
 
Example 3
Source File: StringFieldPropertyWriter.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
@Override
public final void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
    if (broken) {
        fallbackWriter.serializeAsField(bean, gen, prov);
        return;
    }
    String value;
    try {
        value = _propertyAccessor.stringField(bean, _propertyIndex);
    } catch (Throwable t) {
        _handleProblem(bean, gen, prov, t, false);
        return;
    }
    // Null (etc) handling; copied from super-class impl
    if (value == null) {
        if (_nullSerializer != null) {
            gen.writeFieldName(_fastName);
            _nullSerializer.serialize(null, gen, prov);
        } else if (!_suppressNulls) {
            gen.writeFieldName(_fastName);
            prov.defaultSerializeNullValue(gen);
        }
        return;
    }
    if (_suppressableValue != null) {
        if (MARKER_FOR_EMPTY == _suppressableValue) {
            if (value.length() == 0) {
                return;
            }
        } else if (_suppressableValue.equals(value)) {
            return;
        }
    }
    gen.writeFieldName(_fastName);
    gen.writeString(value);
}
 
Example 4
Source File: ObjectMethodPropertyWriter.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
@Override
public final void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
    if (broken) {
        fallbackWriter.serializeAsField(bean, gen, prov);
        return;
    }
    Object value;
    try {
        value = _propertyAccessor.objectGetter(bean, _propertyIndex);
    } catch (Throwable t) {
        _handleProblem(bean, gen, prov, t, false);
        return;
    }
    // Null (etc) handling; copied from super-class impl
    if (value == null) {
        if (_nullSerializer != null) {
            gen.writeFieldName(_fastName);
            _nullSerializer.serialize(null, gen, prov);
        } else if (!_suppressNulls) {
            gen.writeFieldName(_fastName);
            prov.defaultSerializeNullValue(gen);
        }
        return;
    }
    JsonSerializer<Object> ser = _serializer;
    if (ser == null) {
        Class<?> cls = value.getClass();
        PropertySerializerMap map = _dynamicSerializers;
        ser = map.serializerFor(cls);
        if (ser == null) {
            ser = _findAndAddDynamic(map, cls, prov);
        }
    }
    if (_suppressableValue != null) {
        if (MARKER_FOR_EMPTY == _suppressableValue) {
            if (ser.isEmpty(prov, value)) {
                return;
            }
        } else if (_suppressableValue.equals(value)) {
            return;
        }
    }
    if (value == bean) {
        // three choices: exception; handled by call; or pass-through
        if (_handleSelfReference(bean, gen, prov, ser)) {
            return;
        }
    }
    gen.writeFieldName(_fastName);
    if (_typeSerializer == null) {
        ser.serialize(value, gen, prov);
    } else {
        ser.serializeWithType(value, gen, prov, _typeSerializer);
    }
}
 
Example 5
Source File: ObjectMethodPropertyWriter.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
@Override
public final void serializeAsElement(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
    if (broken) {
        fallbackWriter.serializeAsElement(bean, gen, prov);
        return;
    }
    Object value;
    try {
        value = _propertyAccessor.objectGetter(bean, _propertyIndex);
    } catch (Throwable t) {
        _handleProblem(bean, gen, prov, t, true);
        return;
    }
    // Null (etc) handling; copied from super-class impl
    if (value == null) {
        if (_nullSerializer != null) {
            _nullSerializer.serialize(null, gen, prov);
        } else if (_suppressNulls) {
            serializeAsPlaceholder(bean, gen, prov);
        } else {
            prov.defaultSerializeNullValue(gen);
        }
        return;
    }
    JsonSerializer<Object> ser = _serializer;
    if (ser == null) {
        Class<?> cls = value.getClass();
        PropertySerializerMap map = _dynamicSerializers;
        ser = map.serializerFor(cls);
        if (ser == null) {
            ser = _findAndAddDynamic(map, cls, prov);
        }
    }
    if (_suppressableValue != null) {
        if (MARKER_FOR_EMPTY == _suppressableValue) {
            if (ser.isEmpty(prov, value)) {
                serializeAsPlaceholder(bean, gen, prov);
                return;
            }
        } else if (_suppressableValue.equals(value)) {
            serializeAsPlaceholder(bean, gen, prov);
            return;
        }
    }
    if (value == bean) {
        // three choices: exception; handled by call; or pass-through
        if (_handleSelfReference(bean, gen, prov, ser)) {
            return;
        }
    }
    if (_typeSerializer == null) {
        ser.serialize(value, gen, prov);
    } else {
        ser.serializeWithType(value, gen, prov, _typeSerializer);
    }
}
 
Example 6
Source File: ObjectFieldPropertyWriter.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
@Override
public final void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
    if (broken) {
        fallbackWriter.serializeAsField(bean, gen, prov);
        return;
    }
    Object value;
    try {
        value = _propertyAccessor.objectField(bean, _propertyIndex);
    } catch (Throwable t) {
        _handleProblem(bean, gen, prov, t, false);
        return;
    }
    // Null (etc) handling; copied from super-class impl
    if (value == null) {
        if (_nullSerializer != null) {
            gen.writeFieldName(_fastName);
            _nullSerializer.serialize(null, gen, prov);
        } else if (!_suppressNulls) {
            gen.writeFieldName(_fastName);
            prov.defaultSerializeNullValue(gen);
        }
        return;
    }
    JsonSerializer<Object> ser = _serializer;
    if (ser == null) {
        Class<?> cls = value.getClass();
        PropertySerializerMap map = _dynamicSerializers;
        ser = map.serializerFor(cls);
        if (ser == null) {
            ser = _findAndAddDynamic(map, cls, prov);
        }
    }
    if (_suppressableValue != null) {
        if (MARKER_FOR_EMPTY == _suppressableValue) {
            if (ser.isEmpty(prov, value)) {
                return;
            }
        } else if (_suppressableValue.equals(value)) {
            return;
        }
    }
    if (value == bean) {
        // three choices: exception; handled by call; or pass-through
        if (_handleSelfReference(bean, gen, prov, ser)) {
            return;
        }
    }
    gen.writeFieldName(_fastName);
    if (_typeSerializer == null) {
        ser.serialize(value, gen, prov);
    } else {
        ser.serializeWithType(value, gen, prov, _typeSerializer);
    }
}
 
Example 7
Source File: ObjectFieldPropertyWriter.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
@Override
public final void serializeAsElement(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
    if (broken) {
        fallbackWriter.serializeAsElement(bean, gen, prov);
        return;
    }
    Object value;
    try {
        value = _propertyAccessor.objectField(bean, _propertyIndex);
    } catch (Throwable t) {
        _handleProblem(bean, gen, prov, t, true);
        return;
    }
    if (value == null) {
        if (_nullSerializer != null) {
            _nullSerializer.serialize(null, gen, prov);
        } else if (_suppressNulls) {
            serializeAsPlaceholder(bean, gen, prov);
        } else {
            prov.defaultSerializeNullValue(gen);
        }
        return;
    }
    JsonSerializer<Object> ser = _serializer;
    if (ser == null) {
        Class<?> cls = value.getClass();
        PropertySerializerMap map = _dynamicSerializers;
        ser = map.serializerFor(cls);
        if (ser == null) {
            ser = _findAndAddDynamic(map, cls, prov);
        }
    }
    if (_suppressableValue != null) {
        if (MARKER_FOR_EMPTY == _suppressableValue) {
            if (ser.isEmpty(prov, value)) {
                serializeAsPlaceholder(bean, gen, prov);
                return;
            }
        } else if (_suppressableValue.equals(value)) {
            serializeAsPlaceholder(bean, gen, prov);
            return;
        }
    }
    if (value == bean) {
        // three choices: exception; handled by call; or pass-through
        if (_handleSelfReference(bean, gen, prov, ser)) {
            return;
        }
    }
    if (_typeSerializer == null) {
        ser.serialize(value, gen, prov);
    } else {
        ser.serializeWithType(value, gen, prov, _typeSerializer);
    }
}