/**
* nodes which were added to schema via augmentation and are present in data input
*/
- private final Multimap<AugmentationSchema, AbstractNodeDataWithSchema> augmentationsToChild = ArrayListMultimap.create();
+ protected final Multimap<AugmentationSchema, AbstractNodeDataWithSchema> augmentationsToChild = ArrayListMultimap.create();
/**
* remaining data nodes (which aren't added via augment). Every of one them should have the same QName.
*/
- private final List<AbstractNodeDataWithSchema> children = new ArrayList<>();
+ protected final List<AbstractNodeDataWithSchema> children = new ArrayList<>();
public CompositeNodeDataWithSchema(final DataSchemaNode schema) {
super(schema);
try {
reader.peek();
isEmpty = false;
- CompositeNodeDataWithSchema compositeNodeDataWithSchema = new CompositeNodeDataWithSchema(parentNode);
- read(reader, compositeNodeDataWithSchema);
- compositeNodeDataWithSchema.write(writer);
-
+ TopLevelNodeDataWithSchema topLevelNodeDataWithSchema = new TopLevelNodeDataWithSchema(parentNode);
+ read(reader, topLevelNodeDataWithSchema);
+ topLevelNodeDataWithSchema.normalizeTopLevelNode();
+ topLevelNodeDataWithSchema.write(writer);
return this;
// return read(reader);
} catch (EOFException e) {
package org.opendaylight.yangtools.yang.data.codec.gson;
import java.io.IOException;
-
+import java.util.List;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
super(schema);
}
+ List<AbstractNodeDataWithSchema> getListEntry() {
+ return children;
+ }
+
@Override
public void write(final NormalizedNodeStreamWriter writer) throws IOException {
if (((ListSchemaNode) getSchema()).getKeyDefinition().isEmpty()) {
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.codec.gson;
+
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+
+/**
+ * A node which holds top level element.
+ */
+class TopLevelNodeDataWithSchema extends CompositeNodeDataWithSchema {
+
+ public TopLevelNodeDataWithSchema(DataSchemaNode schema) {
+ super(schema);
+ }
+
+ /**
+ * If direct child is of type ListNodeDataWithSchema its direct child - ListEntryNodeDataWitchSchema - is returned.
+ *
+ * ListEntry node should be returned insteand List at top level.
+ */
+ void normalizeTopLevelNode() {
+ if (children.size() == 1 && children.get(0) instanceof ListNodeDataWithSchema) {
+ List<AbstractNodeDataWithSchema> listEntry = ((ListNodeDataWithSchema) children.get(0)).getListEntry();
+ if (listEntry.size() == 1) {
+ children.remove(0);
+ children.add(listEntry.get(0));
+ } else {
+ throw new IllegalStateException("Top level \"list\" element should contain only one list entry.");
+ }
+ }
+ }
+
+}
@Override
public void startUnkeyedListItem(final NodeIdentifier name,final int childSizeHint) throws IllegalStateException {
- Preconditions.checkArgument(getCurrent() instanceof ImmutableUnkeyedListNodeBuilder);
+ Preconditions.checkArgument(getCurrent() instanceof ImmutableUnkeyedListNodeBuilder || getCurrent() instanceof NormalizedNodeResultBuilder);
enter(Builders.unkeyedListEntryBuilder().withNodeIdentifier(name));
}