package com.fasterxml.jackson.dataformat.xml.ser;
import java.util.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.ser.*;
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
import com.fasterxml.jackson.dataformat.xml.util.AnnotationUtil;
import com.fasterxml.jackson.dataformat.xml.util.TypeUtil;
import com.fasterxml.jackson.dataformat.xml.util.XmlInfo;
public class XmlBeanSerializerModifier
extends BeanSerializerModifier
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public XmlBeanSerializerModifier() { }
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config,
BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties)
{
final AnnotationIntrospector intr = config.getAnnotationIntrospector();
for (int i = 0, len = beanProperties.size(); i < len; ++i) {
BeanPropertyWriter bpw = beanProperties.get(i);
final AnnotatedMember member = bpw.getMember();
String ns = AnnotationUtil.findNamespaceAnnotation(intr, member);
Boolean isAttribute = AnnotationUtil.findIsAttributeAnnotation(intr, member);
Boolean isText = AnnotationUtil.findIsTextAnnotation(intr, member);
Boolean isCData = AnnotationUtil.findIsCDataAnnotation(intr, member);
bpw.setInternalSetting(XmlBeanSerializerBase.KEY_XML_INFO,
new XmlInfo(isAttribute, ns, isText, isCData));
if (!TypeUtil.isIndexedType(bpw.getType())) {
continue;
}
PropertyName wrappedName = PropertyName.construct(bpw.getName(), ns);
PropertyName wrapperName = bpw.getWrapperName();
if (wrapperName == null || wrapperName == PropertyName.NO_NAME) {
continue;
}
String localName = wrapperName.getSimpleName();
if (localName == null || localName.length() == 0) {
wrapperName = wrappedName;
}
beanProperties.set(i, new XmlBeanPropertyWriter(bpw, wrapperName, wrappedName));
}
return beanProperties;
}
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config,
BeanDescription beanDesc, JsonSerializer<?> serializer)
{
if (!(serializer instanceof BeanSerializerBase)) {
return serializer;
}
return new XmlBeanSerializer((BeanSerializerBase) serializer);
}
}