- for (Node<?> child : parent.getValue()) {
- DataSchemaNode childSchema = findFirstSchemaForNode(child, parentSchema.getChildNodes());
- if (childSchema instanceof LeafListSchemaNode) {
- foundLeafLists.remove(childSchema);
- } else if (childSchema instanceof ListSchemaNode) {
- foundLists.remove(childSchema);
+ private static void writeValue(final JsonWriter writer, final Object value) throws IOException {
+ writer.value(value == null ? "" : String.valueOf(value));
+ }
+
+ private void handleNoSchemaFound(final JsonWriter writer, final Node<?> node, final CompositeNode parent)
+ throws IOException {
+ if (node instanceof SimpleNode<?>) {
+ List<SimpleNode<?>> nodeLeafList = parent.getSimpleNodesByName(node.getNodeType());
+ if (nodeLeafList.size() == 1) {
+ writeName(node, null, writer);
+ writeValue(writer, node.getValue());
+ } else { // more than 1, write as a json array
+ writeName(node, null, writer);
+ writer.beginArray();
+ for (SimpleNode<?> leafNode : nodeLeafList) {
+ writeValue(writer, leafNode.getValue());
+ }
+
+ writer.endArray();
+ }
+ } else { // CompositeNode
+ Preconditions.checkState(node instanceof CompositeNode,
+ "Data representation of Container should be CompositeNode - %s", node.getNodeType());
+
+ List<CompositeNode> nodeList = parent.getCompositesByName(node.getNodeType());
+ if (nodeList.size() == 1) {
+ writeContainer(writer, (CompositeNode) node, null);
+ } else { // more than 1, write as a json array
+ writeList(writer, parent, (CompositeNode) node, null);