import javax.activation.UnsupportedDataTypeException;
+import org.opendaylight.controller.sal.core.api.mount.MountInstance;
import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO;
import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO.IdentityValue;
private final Set<LeafListSchemaNode> foundLeafLists = new HashSet<>();
private final Set<ListSchemaNode> foundLists = new HashSet<>();
- private final Logger logger = LoggerFactory.getLogger(JsonMapper.class);
+ private MountInstance mountPoint;
+ private final Logger logger = LoggerFactory.getLogger(JsonMapper.class);
- public void write(JsonWriter writer, CompositeNode data, DataNodeContainer schema) throws IOException {
+ public void write(JsonWriter writer, CompositeNode data, DataNodeContainer schema, MountInstance mountPoint) throws IOException {
Preconditions.checkNotNull(writer);
Preconditions.checkNotNull(data);
Preconditions.checkNotNull(schema);
-
+ this.mountPoint = mountPoint;
+
writer.beginObject();
if (schema instanceof ContainerSchemaNode) {
TypeDefinition<?> baseType = RestUtil.resolveBaseTypeFrom(type);
+ if (node.getValue() == null && !(baseType instanceof EmptyTypeDefinition)) {
+ logger.debug("While generationg JSON output null value was found for type "
+ + baseType.getClass().getSimpleName() + ".");
+ }
+
// TODO check InstanceIdentifierTypeDefinition
if (baseType instanceof IdentityrefTypeDefinition) {
if (node.getValue() instanceof QName) {
- IdentityValuesDTO valueDTO = (IdentityValuesDTO) RestCodec.from(baseType).serialize(node.getValue());
+ IdentityValuesDTO valueDTO = (IdentityValuesDTO) RestCodec.from(baseType, mountPoint).serialize(node.getValue());
IdentityValue valueFromDTO = valueDTO.getValuesWithNamespaces().get(0);
- String moduleName = ControllerContext.getInstance().findModuleByNamespace(URI.create(valueFromDTO.getNamespace()));
+ 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 {
logger.debug("Value of " + baseType.getQName().getNamespace() + ":"
- + baseType.getQName().getLocalName() + " is not instance of " + QName.class + " but is " + node.getValue().getClass());
+ + baseType.getQName().getLocalName() + " is not instance of " + QName.class + " but is "
+ + node.getValue().getClass());
writer.value(String.valueOf(node.getValue()));
}
} else if (baseType instanceof DecimalTypeDefinition || baseType instanceof IntegerTypeDefinition
|| baseType instanceof UnsignedIntegerTypeDefinition) {
- writer.value(new NumberForJsonWriter((String) RestCodec.from(baseType).serialize(node.getValue())));
+ 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).serialize(node.getValue())));
+ writer.value(Boolean.parseBoolean((String) RestCodec.from(baseType, mountPoint).serialize(node.getValue())));
} else if (baseType instanceof EmptyTypeDefinition) {
writeEmptyDataTypeToJson(writer);
} else {
- String value = String.valueOf(RestCodec.from(baseType).serialize(node.getValue()));
+ String value = String.valueOf(RestCodec.from(baseType, mountPoint).serialize(node.getValue()));
if (value == null) {
value = String.valueOf(node.getValue());
}