-
- writer.endArray();
- }
-
- private void writeLeafList(JsonWriter writer, SimpleNode<?> node, LeafListSchemaNode schema) throws IOException {
- writer.name(node.getNodeType().getLocalName());
- writer.beginArray();
-
- CompositeNode parent = node.getParent();
- List<SimpleNode<?>> nodeLeafLists = parent.getSimpleNodesByName(node.getNodeType());
- for (SimpleNode<?> nodeLeafList : nodeLeafLists) {
- writeValueOfNodeByType(writer, nodeLeafList, schema.getType());
+ } else {
+ writer.beginObject();
+ writeChildrenOfParent(writer, node, schema);
+ writer.endObject();
+ }
+
+ writer.endArray();
+ }
+
+ private void writeLeafList(final JsonWriter writer, final CompositeNode nodeParent, final SimpleNode<?> node,
+ final LeafListSchemaNode schema) throws IOException {
+ writeName(node, schema, writer);
+ writer.beginArray();
+
+ List<SimpleNode<?>> nodeLeafLists = nodeParent.getSimpleNodesByName(node.getNodeType());
+ for (SimpleNode<?> nodeLeafList : nodeLeafLists) {
+ writeValueOfNodeByType(writer, nodeLeafList, schema.getType(), schema);
+ }
+ writer.endArray();
+ }
+
+ private void writeLeaf(final JsonWriter writer, final SimpleNode<?> node, final LeafSchemaNode schema)
+ throws IOException {
+ writeName(node, schema, writer);
+ writeValueOfNodeByType(writer, node, schema.getType(), schema);
+ }
+
+ private void writeValueOfNodeByType(final JsonWriter writer, final SimpleNode<?> node,
+ final TypeDefinition<?> type, final DataSchemaNode schema) throws IOException {
+
+ TypeDefinition<?> baseType = RestUtil.resolveBaseTypeFrom(type);
+
+ if (node.getValue() == null && !(baseType instanceof EmptyTypeDefinition)) {
+ LOG.debug("While generationg JSON output null value was found for type {}.", baseType.getClass()
+ .getSimpleName());
+ }
+
+ if (baseType instanceof IdentityrefTypeDefinition) {
+ if (node.getValue() instanceof QName) {
+ IdentityValuesDTO valueDTO = (IdentityValuesDTO) RestCodec.from(baseType, mountPoint).serialize(
+ node.getValue());
+ IdentityValue valueFromDTO = valueDTO.getValuesWithNamespaces().get(0);
+ String moduleName;
+ if (mountPoint != null) {
+ moduleName = ControllerContext.getInstance().findModuleNameByNamespace(mountPoint,
+ URI.create(valueFromDTO.getNamespace()));
+ } else {
+ moduleName = ControllerContext.getInstance().findModuleNameByNamespace(
+ URI.create(valueFromDTO.getNamespace()));
+ }
+ writer.value(moduleName + ":" + valueFromDTO.getValue());
+ } else {
+ writeStringRepresentation(writer, node, baseType, QName.class);
+ }
+ } else if (baseType instanceof InstanceIdentifierTypeDefinition) {
+ if (node.getValue() instanceof YangInstanceIdentifier) {
+ IdentityValuesDTO valueDTO = (IdentityValuesDTO) RestCodec.from(baseType, mountPoint).serialize(
+ node.getValue());
+ writeIdentityValuesDTOToJson(writer, valueDTO);
+ } else {
+ writeStringRepresentation(writer, node, baseType, YangInstanceIdentifier.class);