- InstanceIdentifierContext pathContext = t.getInstanceIdentifierContext();
- OutputStreamWriter ouWriter = new OutputStreamWriter(entityStream, Charsets.UTF_8);
- NormalizedNodeStreamWriter jsonWriter = JSONNormalizedNodeStreamWriter.create(pathContext.getSchemaContext(),ouWriter);
- NormalizedNodeWriter nnWriter = NormalizedNodeWriter.forStreamWriter(jsonWriter);
+ final InstanceIdentifierContext<DataSchemaNode> context = (InstanceIdentifierContext<DataSchemaNode>) t.getInstanceIdentifierContext();
+
+ SchemaPath path = context.getSchemaNode().getPath();
+ boolean isDataRoot = false;
+ if (SchemaPath.ROOT.equals(path)) {
+ isDataRoot = true;
+ } else {
+ path = path.getParent();
+ // FIXME: Add proper handling of reading root.
+ }
+
+ final JsonWriter jsonWriter = createJsonWriter(entityStream);
+ final NormalizedNodeWriter nnWriter = createNormalizedNodeWriter(context,path,jsonWriter);
+
+ jsonWriter.beginObject();
+ if(isDataRoot) {
+ writeDataRoot(nnWriter,(ContainerNode) data);
+ } else {
+ if(data instanceof MapEntryNode) {
+ data = ImmutableNodes.mapNodeBuilder(data.getNodeType()).withChild(((MapEntryNode) data)).build();
+ }
+ nnWriter.write(data);
+ }