JsonReader { public Document read( URL url ) throws ParsingException { try { return read(url.openStream(), DEFAULT_INTROSPECT); } catch (IOException e) { throw new ParsingException(e.getMessage(), e, 0, 0); } }  Document read( URL url ); Document read( InputStream stream ); Document read( InputStream stream,
                          Charset charset ); Document read( Reader reader ); Document read( String json ); Document read( InputStream stream,
                          boolean introspectStringValues ); Document read( InputStream stream,
                          Charset charset,
                          boolean introspectStringValues ); Document read( Reader reader,
                          boolean introspectStringValues ); Document read( String json,
                          boolean introspectStringValues ); DocumentSequence readMultiple( InputStream stream ); DocumentSequence readMultiple( InputStream stream,
                                          boolean introspectStringValues ); DocumentSequence readMultiple( Reader reader ); DocumentSequence readMultiple( Reader reader,
                                          boolean introspectStringValues ); static Number parseNumber( String value ); static final boolean DEFAULT_INTROSPECT; }
@Test public void shouldParseEmptyDocument() throws Exception { doc = reader.read("{ }"); }
@Test public void shouldParseEmptyDocumentWithLeadingWhitespace() throws Exception { doc = reader.read(" { }"); }
@Test public void shouldParseEmptyDocumentWithEmbeddedWhitespace() throws Exception { doc = reader.read("{ \n \t \r\n } "); }
@Test public void shouldParseDocumentWithSingleFieldWithStringValue() throws Exception { doc = reader.read("{ \"foo\" : \"bar\" }"); assertField("foo", "bar"); }
@Test public void shouldParseDocumentWithSingleFieldWithBooleanFalseValue() throws Exception { doc = reader.read("{ \"foo\" : false }"); assertField("foo", false); }
@Test public void shouldParseDocumentWithSingleFieldWithBooleanTrueValue() throws Exception { doc = reader.read("{ \"foo\" : true }"); assertField("foo", true); }
@Test public void shouldParseDocumentWithSingleFieldWithIntegerValue() throws Exception { doc = reader.read("{ \"foo\" : 0 }"); assertField("foo", 0); }
@Test public void shouldParseDocumentWithSingleFieldWithLongValue() throws Exception { long val = Integer.MAX_VALUE + 10L; doc = reader.read("{ \"foo\" : " + val + " }"); assertField("foo", val); }
@Test public void shouldParseDocumentWithSingleFieldWithDoubleValue() throws Exception { doc = reader.read("{ \"foo\" : 2.3543 }"); assertField("foo", 2.3543d); }
@Test public void shouldParseDocumentWithMultipleFieldsAndExtraDelimiters() throws Exception { doc = reader.read("{ \"foo\" : 32 ,, \"nested\" : { \"bar\" : \"baz\", \"bom\" : true } ,}"); assertField("foo", 32); doc = doc.getDocument("nested"); assertField("bar", "baz"); assertField("bom", true); }
@Test @FixFor( "MODE-2309" ) public void shouldParseJsonWithControlCharactersInFieldValues() throws Exception { InputStream stream = getClass().getClassLoader().getResourceAsStream("json/example-with-control-characters.json"); doc = reader.read(stream); assertNotNull(doc); assertEquals(6, countFields(doc)); assertField("firstName", "Jane"); assertField("lastName", "Doe"); assertField("fieldWithLF", "This is a value\nwith a line feed"); assertField("fieldWithCRLF", "This is a value\r\nwith a line feed\r\ncarriage return"); doc = doc.getDocument("address"); assertEquals(3, countFields(doc)); assertField("street", "Main Street"); assertField("city", "Memphis"); assertField("zip", 12345); }
@Test @FixFor( "MODE-2082" ) public void shouldParseJsonWithComments() throws Exception { InputStream stream = getClass().getClassLoader().getResourceAsStream("json/example-with-comments.json"); doc = reader.read(stream); assertNotNull(doc); assertEquals(4, countFields(doc)); assertField("firstName", "Jane"); assertField("lastName", "Doe"); doc = doc.getDocument("address"); assertEquals(3, countFields(doc)); assertField("street", "Main assertField("city", "Mem/ phis"); assertField("zip", 12345); }
@Test @FixFor( "MODE-2082" ) public void shouldNotParseJsonWithInvalidComments() throws Exception { InputStream stream = getClass().getClassLoader().getResourceAsStream("json/invalid-example-with-comments.json"); try { doc = reader.read(stream); fail("Expected parsing exception"); } catch (ParsingException e) { } stream = getClass().getClassLoader().getResourceAsStream("json/invalid-example-with-comments2.json"); try { doc = reader.read(stream); fail("Expected parsing exception"); } catch (ParsingException e) { } }
@Test @FixFor( "MODE-2214" ) public void shouldNotParseJsonWithInvalidArray() throws Exception { InputStream stream = getClass().getClassLoader().getResourceAsStream("json/invalid-array-repo-config-1.json"); try { doc = reader.read(stream); fail("Expected parsing exception"); } catch (ParsingException e) { } stream = getClass().getClassLoader().getResourceAsStream("json/invalid-array-repo-config-2.json"); try { doc = reader.read(stream); fail("Expected parsing exception"); } catch (ParsingException e) { } }
@Test @FixFor( "MODE-2317" ) public void shouldParseNonUnicodeEscapeSequence() throws Exception { String url = "jdbc:h2:file:path\\upstream.jboss-integration.modeshape\\modeshape-jcr;DB_CLOSE_DELAY=-1"; doc = reader.read("{ \"url\" : \"" + url + "\"}"); assertField("url", url); InputStream stream = getClass().getClassLoader().getResourceAsStream("json/non-unicode-escape.json"); reader.read(stream); }