use of javax.xml.bind.annotation.XmlMixed in project groovity by disney.
the class ModelXmlWriter method visitObjectField.
public void visitObjectField(String name, Object value) throws Exception {
if (inAttribute) {
writer.write(" ");
writer.write(name);
writer.write("=\"");
super.visitObjectField(name, value);
writer.write("\"");
return;
}
boolean writeTag = true;
Object currentObject = getCurrentObject();
MetaClass mc = GroovySystem.getMetaClassRegistry().getMetaClass(currentObject.getClass());
MetaProperty mp = mc.hasProperty(currentObject, name);
XmlAttribute xa = getAnnotation(mp, XmlAttribute.class);
if (xa != null) {
// attributes are written with open tag
return;
}
String listElementName = null;
if (value instanceof List || (value != null && value.getClass().isArray()) || (mp != null && (mp.getType().isArray() || List.class.isAssignableFrom(mp.getType())))) {
writeTag = false;
listElementName = name;
Map<Class<?>, String> listTypedNames = NO_NAMES;
XmlElementWrapper xew = getAnnotation(mp, XmlElementWrapper.class);
if (xew != null) {
writeTag = true;
if (!"##default".equals(xew.name())) {
name = xew.name();
}
name = getTagName(xew.namespace(), name);
}
XmlElement xe = getAnnotation(mp, XmlElement.class);
if (xe != null) {
if (!"##default".equals(xe.name())) {
listElementName = xe.name();
}
listElementName = getTagName(xe.namespace(), listElementName);
}
if (xe == null) {
XmlElements xes = getAnnotation(mp, XmlElements.class);
if (xes != null) {
listTypedNames = new HashMap<>();
for (int i = 0; i < xes.value().length; i++) {
XmlElement e = xes.value()[i];
listTypedNames.put(e.type(), e.name());
}
}
}
XmlList xel = getAnnotation(mp, XmlList.class);
if (xel != null) {
writeTag = true;
name = listElementName;
value = transformField(mp, value);
}
XmlMixed xm = getAnnotation(mp, XmlMixed.class);
if (xm != null) {
listTypedNames = SKIP_TAG;
}
listElementNames.push(listElementName);
listTypedElementNames.push(listTypedNames);
} else {
XmlElement xe = getAnnotation(mp, XmlElement.class);
if (xe != null) {
if (!"##default".equals(xe.name())) {
name = xe.name();
}
name = getTagName(xe.namespace(), name);
}
}
doDelimit = true;
if (writeTag) {
final String n = name;
writeTag(name, value, o -> {
try {
super.visitObjectField(n, o);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
});
} else {
super.visitObjectField(name, value);
}
if (listElementName != null) {
listElementNames.pop();
listTypedElementNames.pop();
}
}
Aggregations