- Optional<InstanceIdentifierContext> path = getIdentifierWithSchema();
- NormalizedNodeResult resultHolder = new NormalizedNodeResult();
- NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
- JsonParserStream jsonParser = JsonParserStream.create(writer, path.get().getSchemaContext());
- JsonReader reader = new JsonReader(new InputStreamReader(entityStream));
+ final InstanceIdentifierContext<?> path = getInstanceIdentifierContext();
+ if (entityStream.available() < 1) {
+ return new NormalizedNodeContext(path, null);
+ }
+ final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
+ final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
+
+ final SchemaNode parentSchema;
+ if(isPost()) {
+ // FIXME: We need dispatch for RPC.
+ parentSchema = path.getSchemaNode();
+ } else if(path.getSchemaNode() instanceof SchemaContext) {
+ parentSchema = path.getSchemaContext();
+ } else {
+ if (SchemaPath.ROOT.equals(path.getSchemaNode().getPath().getParent())) {
+ parentSchema = path.getSchemaContext();
+ } else {
+ parentSchema = SchemaContextUtil.findDataSchemaNode(path.getSchemaContext(), path.getSchemaNode().getPath().getParent());
+ }
+ }
+
+ final JsonParserStream jsonParser = JsonParserStream.create(writer, path.getSchemaContext(), parentSchema);
+ final JsonReader reader = new JsonReader(new InputStreamReader(entityStream));