Search in sources :

Example 11 with PropertySerializerMap

use of com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap in project jackson-databind by FasterXML.

the class VirtualBeanPropertyWriter method serializeAsField.

/*
    /**********************************************************
    /* PropertyWriter serialization method overrides
    /**********************************************************
     */
@Override
public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception {
    // NOTE: mostly copied from base class, but off-lined get() access
    final Object value = value(bean, gen, prov);
    if (value == null) {
        if (_nullSerializer != null) {
            gen.writeFieldName(_name);
            _nullSerializer.serialize(null, gen, prov);
        }
        return;
    }
    JsonSerializer<Object> ser = _serializer;
    if (ser == null) {
        Class<?> cls = value.getClass();
        PropertySerializerMap m = _dynamicSerializers;
        ser = m.serializerFor(cls);
        if (ser == null) {
            ser = _findAndAddDynamic(m, 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(_name);
    if (_typeSerializer == null) {
        ser.serialize(value, gen, prov);
    } else {
        ser.serializeWithType(value, gen, prov, _typeSerializer);
    }
}
Also used : PropertySerializerMap(com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap)

Aggregations

PropertySerializerMap (com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap)11 IOException (java.io.IOException)3 TypeSerializer (com.fasterxml.jackson.databind.jsontype.TypeSerializer)2