Package com.firefly.utils.json

Examples of com.firefly.utils.json.JsonReader


    reader.close();
  }
 
  @Test
  public void testReadInt4() throws IOException {
    JsonReader reader = new JsonStringReader("   -333 ");
    Assert.assertThat(reader.readInt(), is(-333));
    reader.close();
  }
View Full Code Here


    reader.close();
  }
 
  @Test
  public void testReadInt5() throws IOException {
    JsonReader reader = new JsonStringReader("  { \"testField\": null }");
    Assert.assertThat(reader.isObject(), is(true));
    char[] t1 = "dsffsfsf".toCharArray();
    char[] ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField"));
    Assert.assertThat(reader.isColon(), is(true));
    Assert.assertThat(reader.readInt(), is(0));
    char ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is('}'));
    reader.close();
  }
View Full Code Here

    reader.close();
  }
 
  @Test
  public void testReadLong() throws IOException {
    JsonReader reader = new JsonStringReader("  { \"testField\": -3334}");
    Assert.assertThat(reader.isObject(), is(true));
    char[] t1 = "dsffsfsf".toCharArray();
    char[] ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField"));
    Assert.assertThat(reader.isColon(), is(true));
    Assert.assertThat(reader.readLong(), is(-3334L));
    char ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is('}'));
    reader.close();
  }
View Full Code Here

    reader.close();
  }
 
  @Test
  public void testReadString() throws IOException {
    JsonReader reader = new JsonStringReader("  { \"testField\": \"ddsfseee\",  \"testField2\": \"dddfd\"}");
    Assert.assertThat(reader.isObject(), is(true));
    char[] t1 = "dsffsfsf".toCharArray();
    char[] ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField"));
    Assert.assertThat(reader.isColon(), is(true));
    Assert.assertThat(reader.readString(), is("ddsfseee"));
    char ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is(','));
   
    ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField2"));
    Assert.assertThat(reader.isColon(), is(true));
    Assert.assertThat(reader.readString(), is("dddfd"));
    ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is('}'));
    reader.close();
  }
View Full Code Here

    reader.close();
  }
 
  @Test
  public void testReadString2() throws IOException {
    JsonReader reader = new JsonStringReader("  { \"testField\": \"dds\\\"fseee\",  \"testField2\": \"d\\nddfd\"}");
    Assert.assertThat(reader.isObject(), is(true));
    char[] t1 = "dsffsfsf".toCharArray();
    char[] ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField"));
    Assert.assertThat(reader.isColon(), is(true));
    String s = reader.readString();
    System.out.println(s);
    Assert.assertThat(s, is("dds\"fseee"));
    char ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is(','));
   
    ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField2"));
    Assert.assertThat(reader.isColon(), is(true));
    s = reader.readString();
    System.out.println(s);
    Assert.assertThat(s, is("d\nddfd"));
    ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is('}'));
    reader.close();
  }
View Full Code Here

    reader.close();
  }
 
  @Test
  public void testReadString3() throws IOException {
    JsonReader reader = new JsonStringReader("  { \"testField\": null,  \"testField2\": \"d\\nddfd\"}");
    Assert.assertThat(reader.isObject(), is(true));
    char[] t1 = "dsffsfsf".toCharArray();
    char[] ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField"));
    Assert.assertThat(reader.isColon(), is(true));
    String s = reader.readString();
    Assert.assertThat(s, nullValue());
    char ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is(','));
    reader.close();
  }
View Full Code Here

    reader.close();
  }
 
  @Test
  public void testIsNull() throws IOException {
    JsonReader reader = new JsonStringReader("  { \"testField\": null ,  \"testField2\": \"d\\nddfd\"}");
    Assert.assertThat(reader.isObject(), is(true));
    char[] t1 = "dsffsfsf".toCharArray();
    char[] ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField"));
    Assert.assertThat(reader.isColon(), is(true));
    Assert.assertThat(reader.isNull(), is(true));
    char ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is(','));
   
    ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField2"));
    Assert.assertThat(reader.isColon(), is(true));
    String s = reader.readString();
    System.out.println(s);
    Assert.assertThat(s, is("d\nddfd"));
    ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is('}'));
    reader.close();
  }
View Full Code Here

    reader.close();
  }
 
  @Test
  public void testIsNull2() throws IOException {
    JsonReader reader = new JsonStringReader("  null ".trim());
    Assert.assertThat(reader.isNull(), is(true));
    reader.close();
  }
View Full Code Here

    reader.close();
  }
 
  @Test
  public void testIsNull3() throws IOException {
    JsonReader reader = new JsonStringReader(" nul");
    Assert.assertThat(reader.isNull(), is(false));
    reader.close();
  }
View Full Code Here

    reader.close();
  }
 
  @Test
  public void testReadBoolean() throws IOException {
    JsonReader reader = new JsonStringReader("{ \"testField\": true}");
    Assert.assertThat(reader.isObject(), is(true));
    char[] t1 = "dsffsfsf".toCharArray();
    char[] ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField"));
    Assert.assertThat(reader.isColon(), is(true));
    Assert.assertThat(reader.readBoolean(), is(true));
    char ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is('}'));
    reader.close();
  }
View Full Code Here

TOP

Related Classes of com.firefly.utils.json.JsonReader

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.