Search in sources :

Example 1 with WritableObjectId

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

the class BeanSerializerBase method _serializeWithObjectId.

protected final void _serializeWithObjectId(Object bean, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException {
    final ObjectIdWriter w = _objectIdWriter;
    WritableObjectId objectId = provider.findObjectId(bean, w.generator);
    // If possible, write as id already
    if (objectId.writeAsId(gen, provider, w)) {
        return;
    }
    // If not, need to inject the id:
    Object id = objectId.generateId(bean);
    if (w.alwaysAsId) {
        w.serializer.serialize(id, gen, provider);
        return;
    }
    _serializeObjectId(bean, gen, provider, typeSer, objectId);
}
Also used : ObjectIdWriter(com.fasterxml.jackson.databind.ser.impl.ObjectIdWriter) WritableObjectId(com.fasterxml.jackson.databind.ser.impl.WritableObjectId)

Example 2 with WritableObjectId

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

the class BeanSerializerBase method _serializeWithObjectId.

protected final void _serializeWithObjectId(Object bean, JsonGenerator gen, SerializerProvider provider, boolean startEndObject) throws IOException {
    final ObjectIdWriter w = _objectIdWriter;
    WritableObjectId objectId = provider.findObjectId(bean, w.generator);
    // If possible, write as id already
    if (objectId.writeAsId(gen, provider, w)) {
        return;
    }
    // If not, need to inject the id:
    Object id = objectId.generateId(bean);
    if (w.alwaysAsId) {
        w.serializer.serialize(id, gen, provider);
        return;
    }
    if (startEndObject) {
        gen.writeStartObject(bean);
    }
    objectId.writeAsField(gen, provider, w);
    if (_propertyFilterId != null) {
        serializeFieldsFiltered(bean, gen, provider);
    } else {
        serializeFields(bean, gen, provider);
    }
    if (startEndObject) {
        gen.writeEndObject();
    }
}
Also used : ObjectIdWriter(com.fasterxml.jackson.databind.ser.impl.ObjectIdWriter) WritableObjectId(com.fasterxml.jackson.databind.ser.impl.WritableObjectId)

Example 3 with WritableObjectId

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

the class DefaultSerializerProvider method findObjectId.

/*
    /**********************************************************
    /* Object Id handling
    /**********************************************************
     */
@Override
public WritableObjectId findObjectId(Object forPojo, ObjectIdGenerator<?> generatorType) {
    if (_seenObjectIds == null) {
        _seenObjectIds = _createObjectIdMap();
    } else {
        WritableObjectId oid = _seenObjectIds.get(forPojo);
        if (oid != null) {
            return oid;
        }
    }
    // Not seen yet; must add an entry, return it. For that, we need generator
    ObjectIdGenerator<?> generator = null;
    if (_objectIdGenerators == null) {
        _objectIdGenerators = new ArrayList<ObjectIdGenerator<?>>(8);
    } else {
        for (int i = 0, len = _objectIdGenerators.size(); i < len; ++i) {
            ObjectIdGenerator<?> gen = _objectIdGenerators.get(i);
            if (gen.canUseFor(generatorType)) {
                generator = gen;
                break;
            }
        }
    }
    if (generator == null) {
        generator = generatorType.newForSerialization(this);
        _objectIdGenerators.add(generator);
    }
    WritableObjectId oid = new WritableObjectId(generator);
    _seenObjectIds.put(forPojo, oid);
    return oid;
}
Also used : ObjectIdGenerator(com.fasterxml.jackson.annotation.ObjectIdGenerator) WritableObjectId(com.fasterxml.jackson.databind.ser.impl.WritableObjectId)

Aggregations

WritableObjectId (com.fasterxml.jackson.databind.ser.impl.WritableObjectId)3 ObjectIdWriter (com.fasterxml.jackson.databind.ser.impl.ObjectIdWriter)2 ObjectIdGenerator (com.fasterxml.jackson.annotation.ObjectIdGenerator)1