-
- String value = (String) node.getValue();
- // TODO check Leafref, InstanceIdentifierTypeDefinition, IdentityrefTypeDefinition, UnionTypeDefinition
- if (type.getBaseType() != null) {
- writeValueOfNodeByType(writer, node, type.getBaseType());
- } else if (type instanceof InstanceIdentifierTypeDefinition) {
- writer.value(((InstanceIdentifierTypeDefinition) type).getPathStatement().toString());
- } else if (type instanceof DecimalTypeDefinition
- || type instanceof IntegerTypeDefinition
- || type instanceof UnsignedIntegerTypeDefinition) {
- writer.value(new NumberForJsonWriter(value));
- } else if (type instanceof BooleanTypeDefinition) {
- writer.value(Boolean.parseBoolean(value));
- } else if (type instanceof EmptyTypeDefinition) {
- writer.beginArray();
- writer.nullValue();
- writer.endArray();
+
+ // TODO check InstanceIdentifierTypeDefinition
+ 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 {
+ Object value = node.getValue();
+ logger.debug("Value of " + baseType.getQName().getNamespace() + ":"
+ + baseType.getQName().getLocalName() + " is not instance of " + QName.class + " but is "
+ + (value != null ? value.getClass() : "null"));
+ if (value == null) {
+ writer.value("");
+ } else {
+ writer.value(String.valueOf(value));
+ }
+ }
+ } else if (baseType instanceof DecimalTypeDefinition || baseType instanceof IntegerTypeDefinition
+ || baseType instanceof UnsignedIntegerTypeDefinition) {
+ writer.value(new NumberForJsonWriter((String) RestCodec.from(baseType, mountPoint).serialize(node.getValue())));
+ } else if (baseType instanceof BooleanTypeDefinition) {
+ writer.value(Boolean.parseBoolean((String) RestCodec.from(baseType, mountPoint).serialize(node.getValue())));
+ } else if (baseType instanceof EmptyTypeDefinition) {
+ writeEmptyDataTypeToJson(writer);