final SchemaNode schema = context.getSchemaNode();
final JSONCodecFactory codecs = getCodecFactory(context);
- final URI initialNs;
- if (schema instanceof DataSchemaNode
- && !((DataSchemaNode)schema).isAugmenting()
- && !(schema instanceof SchemaContext)) {
- initialNs = schema.getQName().getNamespace();
- } else if (schema instanceof RpcDefinition) {
- initialNs = schema.getQName().getNamespace();
- } else {
- initialNs = null;
- }
final NormalizedNodeStreamWriter streamWriter = JSONNormalizedNodeStreamWriter.createNestedWriter(
- codecs, path, initialNs, jsonWriter);
+ codecs, path, initialNamespaceFor(schema, depth), jsonWriter);
+
return ParameterAwareNormalizedNodeWriter.forStreamWriter(streamWriter, depth, fields);
}
+ private static URI initialNamespaceFor(final SchemaNode schema, final Integer depth) {
+ if (schema instanceof RpcDefinition) {
+ return schema.getQName().getNamespace();
+ }
+ // For top-level elements we always want to use namespace prefix, hence use a null initial namespace
+ if (depth == null || depth == 0 || schema instanceof SchemaContext) {
+ return null;
+ }
+ return schema instanceof DataSchemaNode && !((DataSchemaNode)schema).isAugmenting()
+ ? schema.getQName().getNamespace() : null;
+ }
+
private static JsonWriter createJsonWriter(final OutputStream entityStream, final boolean prettyPrint) {
if (prettyPrint) {
return JsonWriterFactory.createJsonWriter(
final String jsonResp = optionalResp.get();
assertNotNull("Returned null response", jsonResp);
+ assertThat("Top level module has incorrect format", jsonResp, containsString("\"ietf-interfaces:interface\""));
+ assertThat("Missing \"name\"", jsonResp, containsString("\"name\":\"eth0\""));
assertThat("Missing \"name\"", jsonResp, containsString("\"name\":\"eth0\""));
assertThat("Missing \"type\"", jsonResp, containsString("\"type\":\"ethernetCsmacd\""));
assertThat("Missing \"enabled\"", jsonResp, containsString("\"enabled\":true"));