Package de.odysseus.staxon.json

Examples of de.odysseus.staxon.json.JsonXMLStreamReader


  }

  @Test
  public void testRootArray() throws Exception {
    String input = "[\"charlie\",\"david\"]";
    XMLStreamReader reader = new JsonXMLStreamReader(createSource(new StringReader(input), new QName("bob")), true, ':');
    verify(reader, XMLStreamConstants.START_DOCUMENT, null, null);
    reader.next();
    verify(reader, XMLStreamConstants.PROCESSING_INSTRUCTION, null, null);
    Assert.assertEquals(JsonXMLStreamConstants.MULTIPLE_PI_TARGET, reader.getPITarget());
    Assert.assertEquals("bob", reader.getPIData());
    reader.next();
    verify(reader, XMLStreamConstants.START_ELEMENT, "bob", null);
    reader.next();
    verify(reader, XMLStreamConstants.CHARACTERS, null, "charlie");
    reader.next();
    verify(reader, XMLStreamConstants.END_ELEMENT, "bob", null);
    reader.next();
    verify(reader, XMLStreamConstants.START_ELEMENT, "bob", null);
    reader.next();
    verify(reader, XMLStreamConstants.CHARACTERS, null, "david");
    reader.next();
    verify(reader, XMLStreamConstants.END_ELEMENT, "bob", null);
    reader.next();
    verify(reader, XMLStreamConstants.END_DOCUMENT, null, null);
    reader.close();
  }
View Full Code Here


  }

  @Test
  public void testEmptyArray() throws Exception {
    String input = "[]";
    XMLStreamReader reader = new JsonXMLStreamReader(createSource(new StringReader(input), new QName("bob")), true, ':');
    verify(reader, XMLStreamConstants.START_DOCUMENT, null, null);
    reader.next();
    verify(reader, XMLStreamConstants.PROCESSING_INSTRUCTION, null, null);
    Assert.assertEquals(JsonXMLStreamConstants.MULTIPLE_PI_TARGET, reader.getPITarget());
    Assert.assertEquals("bob", reader.getPIData());
    reader.next();
    verify(reader, XMLStreamConstants.END_DOCUMENT, null, null);
    reader.close();
  }
View Full Code Here

   * <code>&lt;alice charlie="david"&gt;bob&lt;/alice&gt;</code>
   */
  @Test
  public void testAttributes() throws Exception {
    String input = "{\"@charlie\":\"david\",\"$\":\"bob\"}";
    XMLStreamReader reader = new JsonXMLStreamReader(createSource(new StringReader(input), new QName("alice")), true, ':');
    verify(reader, XMLStreamConstants.START_DOCUMENT, null, null);
    reader.next();
    verify(reader, XMLStreamConstants.START_ELEMENT, "alice", null);
    Assert.assertEquals(1, reader.getAttributeCount());
    Assert.assertEquals("david", reader.getAttributeValue(null, "charlie"));
    Assert.assertEquals("david", reader.getAttributeValue(XMLConstants.NULL_NS_URI, "charlie"));
    reader.next();
    verify(reader, XMLStreamConstants.CHARACTERS, null, "bob");
    reader.next();
    verify(reader, XMLStreamConstants.END_ELEMENT, "alice", null);
    reader.next();
    verify(reader, XMLStreamConstants.END_DOCUMENT, null, null);
    reader.close();
  }
View Full Code Here

   * <code>&lt;alice xmlns="http://some-namespace"&gt;bob&lt;/alice&gt;</code>
   */
  @Test
  public void testNamespaces() throws Exception {
    String input = "{\"@xmlns\":\"http://some-namespace\",\"$\":\"bob\"}";
    XMLStreamReader reader = new JsonXMLStreamReader(createSource(new StringReader(input), new QName("alice")), true, ':');
    verify(reader, XMLStreamConstants.START_DOCUMENT, null, null);
    reader.next();
    verify(reader, XMLStreamConstants.START_ELEMENT, "alice", null);
    Assert.assertEquals("http://some-namespace", reader.getNamespaceURI());
    Assert.assertEquals(0, reader.getAttributeCount());
    reader.next();
    verify(reader, XMLStreamConstants.CHARACTERS, null, "bob");
    reader.next();
    verify(reader, XMLStreamConstants.END_ELEMENT, "alice", null);
    Assert.assertEquals("http://some-namespace", reader.getNamespaceURI());
    reader.next();
    verify(reader, XMLStreamConstants.END_DOCUMENT, null, null);
    reader.close();
  }
View Full Code Here

   * <code>&lt;alice xmlns="http://some-namespace"&gt;bob&lt;/alice&gt;</code>
   */
  @Test
  public void testNamespaces2() throws Exception {
    String input = "{\"$\":\"bob\"}";
    XMLStreamReader reader = new JsonXMLStreamReader(createSource(new StringReader(input), new QName("http://some-namespace", "alice")), true, ':');
    verify(reader, XMLStreamConstants.START_DOCUMENT, null, null);
    reader.next();
    verify(reader, XMLStreamConstants.START_ELEMENT, "alice", null);
    Assert.assertEquals("http://some-namespace", reader.getNamespaceURI());
    Assert.assertEquals(0, reader.getAttributeCount());
    reader.next();
    verify(reader, XMLStreamConstants.CHARACTERS, null, "bob");
    reader.next();
    verify(reader, XMLStreamConstants.END_ELEMENT, "alice", null);
    Assert.assertEquals("http://some-namespace", reader.getNamespaceURI());
    reader.next();
    verify(reader, XMLStreamConstants.END_DOCUMENT, null, null);
    reader.close();
  }
View Full Code Here

   * <code>&lt;alice&gt;bob&lt;/alice&gt;</code>
   */
  @Test
  public void testTextContent() throws Exception {
    String input = "\"bob\"";
    XMLStreamReader reader = new JsonXMLStreamReader(createSource(new StringReader(input), new QName("alice")), true, ':');
    verify(reader, XMLStreamConstants.START_DOCUMENT, null, null);
    reader.next();
    verify(reader, XMLStreamConstants.START_ELEMENT, "alice", null);
    reader.next();
    verify(reader, XMLStreamConstants.CHARACTERS, null, "bob");
    reader.next();
    verify(reader, XMLStreamConstants.END_ELEMENT, "alice", null);
    reader.next();
    verify(reader, XMLStreamConstants.END_DOCUMENT, null, null);
    reader.close();
  }
View Full Code Here

   * <code>&lt;alice&gt;&lt;bob&gt;charlie&lt;/bob&gt;&lt;david&gt;edgar&lt;/david&gt;&lt;/alice&gt;</code>
   */
  @Test
  public void testNested() throws Exception {
    String input = "{\"bob\":\"charlie\",\"david\":\"edgar\"}";
    XMLStreamReader reader = new JsonXMLStreamReader(createSource(new StringReader(input), new QName("alice")), true, ':');
    verify(reader, XMLStreamConstants.START_DOCUMENT, null, null);
    reader.next();
    verify(reader, XMLStreamConstants.START_ELEMENT, "alice", null);
    reader.next();
    verify(reader, XMLStreamConstants.START_ELEMENT, "bob", null);
    reader.next();
    verify(reader, XMLStreamConstants.CHARACTERS, null, "charlie");
    reader.next();
    verify(reader, XMLStreamConstants.END_ELEMENT, "bob", null);
    reader.next();
    verify(reader, XMLStreamConstants.START_ELEMENT, "david", null);
    reader.next();
    verify(reader, XMLStreamConstants.CHARACTERS, null, "edgar");
    reader.next();
    verify(reader, XMLStreamConstants.END_ELEMENT, "david", null);
    reader.next();
    verify(reader, XMLStreamConstants.END_ELEMENT, "alice", null);
    reader.next();
    verify(reader, XMLStreamConstants.END_DOCUMENT, null, null);
    reader.close();
  }
View Full Code Here

   * <code>&lt;alice&gt;&lt;bob&gt;charlie&lt;/bob&gt;&lt;bob&gt;david&lt;/bob&gt;&lt;/alice&gt;</code>
   */
  @Test
  public void testArray() throws Exception {
    String input = "{\"bob\":[\"charlie\",\"david\"]}";
    XMLStreamReader reader = new JsonXMLStreamReader(createSource(new StringReader(input), new QName("alice")), true, ':');
    verify(reader, XMLStreamConstants.START_DOCUMENT, null, null);
    reader.next();
    verify(reader, XMLStreamConstants.START_ELEMENT, "alice", null);
    reader.next();
    verify(reader, XMLStreamConstants.PROCESSING_INSTRUCTION, null, null);
    Assert.assertEquals(JsonXMLStreamConstants.MULTIPLE_PI_TARGET, reader.getPITarget());
    Assert.assertEquals("bob", reader.getPIData());
    reader.next();
    verify(reader, XMLStreamConstants.START_ELEMENT, "bob", null);
    reader.next();
    verify(reader, XMLStreamConstants.CHARACTERS, null, "charlie");
    reader.next();
    verify(reader, XMLStreamConstants.END_ELEMENT, "bob", null);
    reader.next();
    verify(reader, XMLStreamConstants.START_ELEMENT, "bob", null);
    reader.next();
    verify(reader, XMLStreamConstants.CHARACTERS, null, "david");
    reader.next();
    verify(reader, XMLStreamConstants.END_ELEMENT, "bob", null);
    reader.next();
    verify(reader, XMLStreamConstants.END_ELEMENT, "alice", null);
    reader.next();
    verify(reader, XMLStreamConstants.END_DOCUMENT, null, null);
    reader.close();
  }
View Full Code Here

TOP

Related Classes of de.odysseus.staxon.json.JsonXMLStreamReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.