import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
+import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.regex.Pattern;
import javax.xml.transform.dom.DOMSource;
}
private void writeObject(Node node) throws IOException {
- String previousNodeName = "";
+ final var previousNodeNames = new HashSet<String>();
while (node != null) {
if (Node.ELEMENT_NODE == node.getNodeType()) {
- if (!node.getNodeName().equals(previousNodeName)) {
- previousNodeName = node.getNodeName();
- writer.name(node.getNodeName());
+ final var nodeName = node.getNodeName();
+ if (previousNodeNames.add(nodeName)) {
+ writer.name(nodeName);
writeXmlNode(node);
}
}
executebug8927Test("/bug8927/xml/scalar_array.xml", "/bug8927/json/scalar_array.json");
}
+ @Test
+ public void yt1302TestFlatArray() throws Exception {
+ executeYt1302Test("/yt1302/xml/flat-array.xml", "/yt1302/json/flat-array.json");
+ }
+
+ @Test
+ public void yt1302TestArrayOfArray() throws Exception {
+ executeYt1302Test("/yt1302/xml/array-of-array.xml", "/yt1302/json/array-of-array.json");
+ }
+
private void executebug8927Test(final String inputXmlFile, final String expectedJsonFile) throws Exception {
+ verifyExpectedJson(inputXmlFile, expectedJsonFile, "bug8927.test", "2017-01-01", "foo");
+ }
+
+ private void executeYt1302Test(final String inputXmlFile, final String expectedJsonFile) throws Exception {
+ verifyExpectedJson(inputXmlFile, expectedJsonFile, "yt1302.test", "2022-10-11", "data");
+ }
+
+ private void verifyExpectedJson(final String inputXmlFile, final String expectedJsonFile,
+ final String namespace, final String revision, final String localName) throws Exception {
final InputStream resourceAsStream = AnyXmlSupportTest.class.getResourceAsStream(inputXmlFile);
final NormalizedNodeResult result = new NormalizedNodeResult();
loadXmlToNormalizedNodes(resourceAsStream, result, schemaContext);
assertTrue(result.getResult() instanceof ContainerNode);
final DataContainerChild data = ((ContainerNode) result.getResult())
- .childByArg(new NodeIdentifier(QName.create("bug8927.test", "2017-01-01", "foo")));
+ .childByArg(new NodeIdentifier(QName.create(namespace, revision, localName)));
assertNotNull(data);
final String jsonOutput = normalizedNodesToJsonString(data, schemaContext);
assertEquals(JsonParser.parseReader(new FileReader(
- new File(getClass().getResource(expectedJsonFile).toURI()), StandardCharsets.UTF_8)),
- JsonParser.parseString(jsonOutput));
+ new File(getClass().getResource(expectedJsonFile).toURI()), StandardCharsets.UTF_8)),
+ JsonParser.parseString(jsonOutput));
}
private static DOMSource getParsedAnyXmlValue(final NormalizedNode transformedInput, final QName anyxmlName) {
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+<data xmlns="yt1302.test">
+ <anyxml-data>
+ <list-a>
+ <list-a>
+ <leaflist-a>alpha</leaflist-a>
+ <leaflist-a>beta</leaflist-a>
+ </list-a>
+ <list-b>
+ <leaflist-b>gamma</leaflist-b>
+ <leaflist-b>delta</leaflist-b>
+ </list-b>
+ <list-a>
+ <leaf-a>epsilon</leaf-a>
+ </list-a>
+ <list-b>
+ <leaf-b>zeta</leaf-b>
+ </list-b>
+ </list-a>
+ <list-b>
+ <leaf-b>eta</leaf-b>
+ </list-b>
+ <list-a>
+ <leaflist-a>theta</leaflist-a>
+ <leaflist-a>iota</leaflist-a>
+ </list-a>
+ <list-b>
+ <leaf-b>kappa</leaf-b>
+ </list-b>
+ </anyxml-data>
+</data>
+</root>