package com.fasterxml.jackson.databind.ser.impl;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.databind.util.NameTransformer;
import java.io.IOException;
import java.util.Set;
public class UnwrappingBeanSerializer
extends BeanSerializerBase
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final NameTransformer _nameTransformer;
public UnwrappingBeanSerializer(BeanSerializerBase src, NameTransformer transformer) {
super(src, transformer);
_nameTransformer = transformer;
}
public UnwrappingBeanSerializer(UnwrappingBeanSerializer src,
ObjectIdWriter objectIdWriter) {
super(src, objectIdWriter);
_nameTransformer = src._nameTransformer;
}
public UnwrappingBeanSerializer(UnwrappingBeanSerializer src,
ObjectIdWriter objectIdWriter, Object filterId) {
super(src, objectIdWriter, filterId);
_nameTransformer = src._nameTransformer;
}
protected UnwrappingBeanSerializer(UnwrappingBeanSerializer src, Set<String> toIgnore) {
this(src, toIgnore, null);
}
protected UnwrappingBeanSerializer(UnwrappingBeanSerializer src, Set<String> toIgnore, Set<String> toInclude) {
super(src, toIgnore, toInclude);
_nameTransformer = src._nameTransformer;
}
protected UnwrappingBeanSerializer(UnwrappingBeanSerializer src,
BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties) {
super(src, properties, filteredProperties);
_nameTransformer = src._nameTransformer;
}
@Override
public JsonSerializer<Object> unwrappingSerializer(NameTransformer transformer) {
return new UnwrappingBeanSerializer(this, transformer);
}
@Override
public boolean isUnwrappingSerializer() {
return true;
}
@Override
public BeanSerializerBase withObjectIdWriter(ObjectIdWriter objectIdWriter) {
return new UnwrappingBeanSerializer(this, objectIdWriter);
}
@Override
public BeanSerializerBase withFilterId(Object filterId) {
return new UnwrappingBeanSerializer(this, _objectIdWriter, filterId);
}
@Override
protected BeanSerializerBase withByNameInclusion(Set<String> toIgnore, Set<String> toInclude) {
return new UnwrappingBeanSerializer(this, toIgnore, toInclude);
}
@Override
protected BeanSerializerBase withProperties(BeanPropertyWriter[] properties,
BeanPropertyWriter[] filteredProperties) {
return new UnwrappingBeanSerializer(this, properties, filteredProperties);
}
@Override
protected BeanSerializerBase asArraySerializer() {
return this;
}
@Override
public final void serialize(Object bean, JsonGenerator gen, SerializerProvider provider) throws IOException
{
gen.setCurrentValue(bean);
if (_objectIdWriter != null) {
_serializeWithObjectId(bean, gen, provider, false);
return;
}
if (_propertyFilterId != null) {
serializeFieldsFiltered(bean, gen, provider);
} else {
serializeFields(bean, gen, provider);
}
}
@Override
public void serializeWithType(Object bean, JsonGenerator gen, SerializerProvider provider,
TypeSerializer typeSer) throws IOException
{
if (provider.isEnabled(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS)) {
provider.reportBadDefinition(handledType(),
"Unwrapped property requires use of type information: cannot serialize without disabling `SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS`");
}
gen.setCurrentValue(bean);
if (_objectIdWriter != null) {
_serializeWithObjectId(bean, gen, provider, typeSer);
return;
}
if (_propertyFilterId != null) {
serializeFieldsFiltered(bean, gen, provider);
} else {
serializeFields(bean, gen, provider);
}
}
@Override public String toString() {
return "UnwrappingBeanSerializer for "+handledType().getName();
}
}