- for (Node<?> child : parent.getChildren()) {
- DataSchemaNode childSchema = findFirstSchemaForNode(child, parentSchema.getChildNodes());
- if (childSchema instanceof LeafListSchemaNode) {
- foundLeafLists.remove((LeafListSchemaNode) childSchema);
- } else if (childSchema instanceof ListSchemaNode) {
- foundLists.remove((ListSchemaNode) childSchema);
+ private void writeValue( final JsonWriter writer, Object value ) throws IOException {
+ if( value != null ) {
+ writer.value( String.valueOf( value ) );
+ }
+ else {
+ writer.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 - " + 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 );