@Override @Nullable public Object deserialize(Object o, @NotNull Object... nodes) { assert nodes.length > 0; Object[] children; if (nodes.length == 1) { children = JDOMUtil.getContent((Element) nodes[0]); } else { String name = ((Element) nodes[0]).getName(); List<Content> childrenList = new SmartList<Content>(); for (Object node : nodes) { assert ((Element) node).getName().equals(name); childrenList.addAll(((Element) node).getContent()); } children = ArrayUtil.toObjectArray(childrenList); } if (children.length == 0) { children = new Object[] {new Text(myTagAnnotation.textIfEmpty())}; } assert myBinding != null; Object v = myBinding.deserialize(myAccessor.read(o), children); Object value = XmlSerializerImpl.convert(v, myAccessor.getValueClass()); myAccessor.write(o, value); return o; }
public Object deserialize(Object o, @NotNull Object... nodes) { Map map = (Map) o; map.clear(); final Object[] childNodes; if (myMapAnnotation == null || myMapAnnotation.surroundWithTag()) { assert nodes.length == 1; Element m = (Element) nodes[0]; childNodes = JDOMUtil.getContent(m); } else { childNodes = nodes; } for (Object childNode : childNodes) { if (XmlSerializerImpl.isIgnoredNode(childNode)) continue; Element entry = (Element) childNode; Object k = null; Object v = null; assert entry.getName().equals(getEntryAttributeName()); Attribute keyAttr = entry.getAttribute(getKeyAttributeValue()); if (keyAttr != null) { k = myKeyBinding.deserialize(o, keyAttr); } else { if (myMapAnnotation != null && !myMapAnnotation.surroundKeyWithTag()) { final Object[] children = JDOMUtil.getContent(entry); for (Object child : children) { if (myKeyBinding.isBoundTo(child)) { k = myKeyBinding.deserialize(o, child); break; } } assert k != null : "no key found"; } else { final Object keyNode = entry.getChildren(getKeyAttributeValue()).get(0); k = myKeyBinding.deserialize(o, JDOMUtil.getContent((Element) keyNode)); } } Attribute valueAttr = entry.getAttribute(getValueAttributeName()); if (valueAttr != null) { v = myValueBinding.deserialize(o, valueAttr); } else { if (myMapAnnotation != null && !myMapAnnotation.surroundValueWithTag()) { final Object[] children = JDOMUtil.getContent(entry); for (Object child : children) { if (myValueBinding.isBoundTo(child)) { v = myValueBinding.deserialize(o, child); break; } } assert v != null : "no value found"; } else { final Object valueNode = entry.getChildren(getValueAttributeName()).get(0); v = myValueBinding.deserialize( o, XmlSerializerImpl.getNotIgnoredContent((Element) valueNode)); } } //noinspection unchecked map.put(k, v); } return map; }