use of jakarta.xml.bind.annotation.XmlList in project jOOQ by jOOQ.
the class MiniJAXB method unmarshal0.
private static void unmarshal0(Object result, Element element, Map<Class<?>, Map<String, Field>> fieldsByClass) throws Exception {
if (result == null)
return;
Map<String, Field> map = fieldsByElementName(fieldsByClass, result.getClass());
NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node item = childNodes.item(i);
if (item.getNodeType() != Node.ELEMENT_NODE)
continue;
Element childElement = (Element) item;
Field child = map.get(childElement.getTagName());
if (child == null)
child = map.get(childElement.getLocalName());
// skip unknown elements
if (child == null)
continue;
XmlElementWrapper w = child.getAnnotation(XmlElementWrapper.class);
XmlElement e = child.getAnnotation(XmlElement.class);
XmlJavaTypeAdapter a = child.getAnnotation(XmlJavaTypeAdapter.class);
XmlList l = child.getAnnotation(XmlList.class);
String childName = child.getName();
Class<?> childType = child.getType();
if (List.class.isAssignableFrom(childType) && w != null && e != null) {
List<Object> list = new ArrayList<Object>();
unmarshalList0(list, childElement, e.name(), (Class<?>) ((ParameterizedType) child.getGenericType()).getActualTypeArguments()[0], fieldsByClass);
Reflect.on(result).set(childName, list);
} else if (List.class.isAssignableFrom(childType) && l != null) {
List<Object> list = new ArrayList<Object>(asList(childElement.getTextContent().split(" +")));
Reflect.on(result).set(childName, Convert.convert(list, (Class<?>) ((ParameterizedType) child.getGenericType()).getActualTypeArguments()[0]));
} else if (childType.getAnnotation(XmlEnum.class) != null) {
Reflect.on(result).set(childName, Reflect.onClass(childType).call("fromValue", childElement.getTextContent().trim()));
} else if (childType.getAnnotation(XmlType.class) != null) {
Object object = Reflect.on(childType).create().get();
Reflect.on(result).set(childName, object);
unmarshal0(object, childElement, fieldsByClass);
} else if (a != null) {
@SuppressWarnings("unchecked") XmlAdapter<Object, Object> adapter = a.value().getDeclaredConstructor().newInstance();
Reflect.on(result).set(childName, adapter.unmarshal(childElement.getTextContent().trim()));
} else {
Reflect.on(result).set(childName, Convert.convert(childElement.getTextContent().trim(), childType));
}
}
}
Aggregations