Package com.firefly.utils.json.io

Examples of com.firefly.utils.json.io.JsonStringReader


    reader.close();
  }
 
  @Test
  public void testReadBoolean5() 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.readBoolean(), is(false));
    char ch = reader.readAndSkipBlank();
    Assert.assertThat(ch, is('}'));
    reader.close();
  }
View Full Code Here


    reader.close();
  }
 
  @Test
  public void testSkipValue() throws IOException {
    JsonReader reader = new JsonStringReader("{ \"testField\": null, \"ssdd\" : \"sdf\\\"sdfsdf\" }");
    Assert.assertThat(reader.isObject(), is(true));
    Assert.assertThat(Arrays.equals("testField".toCharArray(), reader.readChars()), is(true));
    Assert.assertThat(reader.isColon(), is(true));
    reader.skipValue();
   
    Assert.assertThat(reader.isComma(), is(true));
    Assert.assertThat(Arrays.equals("ssdd".toCharArray(), reader.readChars()), is(true));
    Assert.assertThat(reader.isColon(), is(true));
    reader.skipValue();
    reader.close();
  }
View Full Code Here

    reader.close();
  }
 
  @Test
  public void testSkipValue2() throws IOException {
    JsonReader reader = new JsonStringReader("{ \"testField\": [ [[2 , 3],[3]], [[3,4]] ], \"ssdd\" : \"sdf\\\"sdfsdf\" }");
    Assert.assertThat(reader.isObject(), is(true));
    Assert.assertThat(Arrays.equals("testField".toCharArray(), reader.readChars()), is(true));
    Assert.assertThat(reader.isColon(), is(true));
    reader.skipValue();
   
    Assert.assertThat(reader.isComma(), is(true));
    Assert.assertThat(Arrays.equals("ssdd".toCharArray(), reader.readChars()), is(true));
    Assert.assertThat(reader.isColon(), is(true));
    reader.skipValue();
    reader.close();
  }
View Full Code Here

    reader.close();
  }
 
  @Test
  public void testSkipValue3() throws IOException {
    JsonReader reader = new JsonStringReader("{ \"testField\": [ [[{} , {\"t1\" : { \"t2\": {\"t3\" : [\"332f\", \"dsfdsf\\\"sd\"] } } }],[]], [[3,4]] ], \"ssdd\" : \"sdf\\\"sdfsdf\" }");
    Assert.assertThat(reader.isObject(), is(true));
    Assert.assertThat(Arrays.equals("testField".toCharArray(), reader.readChars()), is(true));
    Assert.assertThat(reader.isColon(), is(true));
    reader.skipValue();
   
    Assert.assertThat(reader.isComma(), is(true));
    Assert.assertThat(Arrays.equals("ssdd".toCharArray(), reader.readChars()), is(true));
    Assert.assertThat(reader.isColon(), is(true));
    reader.skipValue();
    reader.close();
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  public static <T> T toObject(String json, Class<T> clazz) {
    JsonReader reader = null;
    T ret = null;
    try {
      reader = new JsonStringReader(json);
      ret = (T) ParserStateMachine.toObject(reader, clazz);
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if(reader != null)
View Full Code Here

import static org.hamcrest.Matchers.*;

public class TestReader {
  @Test
  public void testReadAndSkipBlank() throws IOException {
    JsonReader reader = new JsonStringReader("  tt".trim());
    Assert.assertThat(reader.readAndSkipBlank(), is('t'));
//    Assert.assertThat(reader.position(), is(1));
    reader.close();
  }
View Full Code Here

    reader.close();
  }
 
  @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

    reader.close();
  }
 
  @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

    reader.close();
  }
 
  @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

    reader.close();
  }
 
  @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('}'));
    reader.close();
  }
View Full Code Here

TOP

Related Classes of com.firefly.utils.json.io.JsonStringReader

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.