X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frest%2Fimpl%2FXmlMapper.java;h=a3d658e7bfec43bca4dc743a460cab8bd6cea9de;hb=85ed33d7b90013a393fedcf4947307fbc7248fc2;hp=f580b3216c83351ace4110455255db320f717a4c;hpb=d468a5db1e6fe2c3949d3f6227c0645c6777ecb5;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlMapper.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlMapper.java index f580b3216c..a3d658e7bf 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlMapper.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlMapper.java @@ -7,9 +7,9 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import org.opendaylight.controller.sal.restconf.impl.RestCodec; import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO; import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO.IdentityValue; +import org.opendaylight.controller.sal.restconf.impl.RestCodec; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.opendaylight.yangtools.yang.data.api.Node; @@ -64,9 +64,9 @@ public class XmlMapper { Element itemEl = doc.createElementNS(dataType.getNamespace().toString(), dataType.getLocalName()); if (data instanceof SimpleNode) { if (schema instanceof LeafListSchemaNode) { - writeValueOfNodeByType(itemEl, (SimpleNode) data, ((LeafListSchemaNode) schema).getType()); + writeValueOfNodeByType(itemEl, (SimpleNode) data, ((LeafListSchemaNode) schema).getType(), (DataSchemaNode) schema); } else if (schema instanceof LeafSchemaNode) { - writeValueOfNodeByType(itemEl, (SimpleNode) data, ((LeafSchemaNode) schema).getType()); + writeValueOfNodeByType(itemEl, (SimpleNode) data, ((LeafSchemaNode) schema).getType(), (DataSchemaNode) schema); } else { Object value = data.getValue(); if (value != null) { @@ -91,9 +91,9 @@ public class XmlMapper { return itemEl; } - private void writeValueOfNodeByType(Element element, SimpleNode node, TypeDefinition type) { + private void writeValueOfNodeByType(Element element, SimpleNode node, TypeDefinition type, DataSchemaNode schema) { - TypeDefinition baseType = resolveBaseTypeFrom(type); + TypeDefinition baseType = RestUtil.resolveBaseTypeFrom(type); if (baseType instanceof IdentityrefTypeDefinition) { if (node.getValue() instanceof QName) { @@ -111,9 +111,12 @@ public class XmlMapper { element.setTextContent(String.valueOf(node.getValue())); } } else { - Object value = node.getValue(); - if (value != null) { - element.setTextContent(String.valueOf(value)); + if (node.getValue() != null) { + String value = String.valueOf(RestCodec.from(baseType).serialize(node.getValue())); + if (value.equals("null")) { + value = String.valueOf(node.getValue()); + } + element.setTextContent(value); } } } @@ -136,8 +139,4 @@ public class XmlMapper { return null; } - private TypeDefinition resolveBaseTypeFrom(TypeDefinition type) { - return type.getBaseType() != null ? resolveBaseTypeFrom(type.getBaseType()) : type; - } - }