use of com.fasterxml.jackson.databind.jsontype.TypeSerializer in project jackson-databind by FasterXML.
the class IteratorSerializer method serializeContents.
@Override
public void serializeContents(Iterator<?> value, JsonGenerator g, SerializerProvider provider) throws IOException {
if (!value.hasNext()) {
return;
}
JsonSerializer<Object> serializer = _elementSerializer;
if (serializer == null) {
_serializeDynamicContents(value, g, provider);
return;
}
final TypeSerializer typeSer = _valueTypeSerializer;
do {
Object elem = value.next();
if (elem == null) {
provider.defaultSerializeNull(g);
} else if (typeSer == null) {
serializer.serialize(elem, g, provider);
} else {
serializer.serializeWithType(elem, g, provider, typeSer);
}
} while (value.hasNext());
}
use of com.fasterxml.jackson.databind.jsontype.TypeSerializer in project jackson-databind by FasterXML.
the class IterableSerializer method serializeContents.
@Override
public void serializeContents(Iterable<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
Iterator<?> it = value.iterator();
if (it.hasNext()) {
final TypeSerializer typeSer = _valueTypeSerializer;
JsonSerializer<Object> prevSerializer = null;
Class<?> prevClass = null;
do {
Object elem = it.next();
if (elem == null) {
provider.defaultSerializeNull(jgen);
continue;
}
JsonSerializer<Object> currSerializer = _elementSerializer;
if (currSerializer == null) {
// Minor optimization to avoid most lookups:
Class<?> cc = elem.getClass();
if (cc == prevClass) {
currSerializer = prevSerializer;
} else {
currSerializer = provider.findValueSerializer(cc, _property);
prevSerializer = currSerializer;
prevClass = cc;
}
}
if (typeSer == null) {
currSerializer.serialize(elem, jgen, provider);
} else {
currSerializer.serializeWithType(elem, jgen, provider, typeSer);
}
} while (it.hasNext());
}
}
use of com.fasterxml.jackson.databind.jsontype.TypeSerializer in project jackson-databind by FasterXML.
the class ObjectArraySerializer method serializeContentsUsing.
public void serializeContentsUsing(Object[] value, JsonGenerator jgen, SerializerProvider provider, JsonSerializer<Object> ser) throws IOException {
final int len = value.length;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
Object elem = null;
try {
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(jgen);
continue;
}
if (typeSer == null) {
ser.serialize(elem, jgen, provider);
} else {
ser.serializeWithType(elem, jgen, provider, typeSer);
}
}
} catch (Exception e) {
wrapAndThrow(provider, e, elem, i);
}
}
use of com.fasterxml.jackson.databind.jsontype.TypeSerializer in project jackson-databind by FasterXML.
the class BeanSerializerFactory method removeOverlappingTypeIds.
/**
* Helper method called to ensure that we do not have "duplicate" type ids.
* Added to resolve [databind#222]
*
* @since 2.6
*/
protected List<BeanPropertyWriter> removeOverlappingTypeIds(SerializerProvider prov, BeanDescription beanDesc, BeanSerializerBuilder builder, List<BeanPropertyWriter> props) {
for (int i = 0, end = props.size(); i < end; ++i) {
BeanPropertyWriter bpw = props.get(i);
TypeSerializer td = bpw.getTypeSerializer();
if ((td == null) || (td.getTypeInclusion() != As.EXTERNAL_PROPERTY)) {
continue;
}
String n = td.getPropertyName();
PropertyName typePropName = PropertyName.construct(n);
for (BeanPropertyWriter w2 : props) {
if ((w2 != bpw) && w2.wouldConflictWithName(typePropName)) {
bpw.assignTypeSerializer(null);
break;
}
}
}
return props;
}
Aggregations