Package com.firefly.utils.json

Examples of com.firefly.utils.json.JsonReader.readField()


 
  @Test
  public void testReadField() throws IOException {
    JsonReader reader = new JsonStringReader("  \"testField\":");
    char[] t1 = "test".toCharArray();
    char[] ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField"));
//    Assert.assertThat(reader.get(reader.position()), is(':'));
    reader.close();
  }
 
View Full Code Here


 
  @Test
  public void testReadField2() throws IOException {
    JsonReader reader = new JsonStringReader("  \"testField\" :");
    char[] t1 = "testField".toCharArray();
    char[] ret = reader.readField(t1);
    Assert.assertThat(ret, nullValue());
    Assert.assertThat(reader.isColon(), is(true));
    reader.close();
  }
 
View Full Code Here

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

  @Test
  public void testReadDouble() throws IOException {
    JsonReader reader = new JsonStringReader("  { \"testField\": 3332.44 }");
    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.readDouble(), is(3332.44));
    char ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is('}'));
View Full Code Here

  @Test
  public void testReadDouble2() throws IOException {
    JsonReader reader = new JsonStringReader("  { \"testField\": -17.44320 , \"testField2\": \" -334\" }");
    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.readDouble(), is(-17.44320));
    Assert.assertThat(reader.isComma(), is(true));
   
View Full Code Here

    Assert.assertThat(new String(ret), is("testField"));
    Assert.assertThat(reader.isColon(), is(true));
    Assert.assertThat(reader.readDouble(), is(-17.44320));
    Assert.assertThat(reader.isComma(), is(true));
   
    ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField2"));
    Assert.assertThat(reader.isColon(), is(true));
    Assert.assertThat(reader.readInt(), is(-334));
    reader.close();
  }
View Full Code Here

  @Test
  public void testReadFloat() throws IOException {
    JsonReader reader = new JsonStringReader("  { \"testField\": \" -17.44320\" , \"testField2\": \" -334\" }");
    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.readFloat(), is(-17.44320F));
    Assert.assertThat(reader.isComma(), is(true));
   
View Full Code Here

    Assert.assertThat(new String(ret), is("testField"));
    Assert.assertThat(reader.isColon(), is(true));
    Assert.assertThat(reader.readFloat(), is(-17.44320F));
    Assert.assertThat(reader.isComma(), is(true));
   
    ret = reader.readField(t1);
    Assert.assertThat(new String(ret), is("testField2"));
    Assert.assertThat(reader.isColon(), is(true));
    Assert.assertThat(reader.readInt(), is(-334));
    reader.close();
  }
View Full Code Here

  @Test
  public void testReadInt() throws IOException {
    JsonReader reader = new JsonStringReader("  { \"testField\": 333 }");
    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(333));
    char ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is('}'));
View Full Code Here

  @Test
  public void testReadInt2() throws IOException {
    JsonReader reader = new JsonStringReader("  { \"testField\": \" -333\" , \"testField2\": \" -334\" }");
    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(-333));
    Assert.assertThat(reader.isComma(), is(true));
   
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.