Package org.exoplatform.ws.frameworks.json

Examples of org.exoplatform.ws.frameworks.json.JsonParser


   public void testConvertFromStringValue() throws Exception
   {
      String jsonString =
         "{\"b\":\"1\", \"s\":\"2\" , \"i\":\"3\", \"l\":\"4\",\"f\":\"1.05\",\"d\":\"1.1\",\"bool\":\"true\"}";
      JsonParser jsonParser = new JsonParserImpl();
      JsonDefaultHandler handler = new JsonDefaultHandler();
      jsonParser.parse(new ByteArrayInputStream(jsonString.getBytes()), handler);
      JsonValue jsonValue = handler.getJsonObject();
      //System.out.println(jsonValue);
      ConvertFromStringValuBean o = ObjectBuilder.createObject(ConvertFromStringValuBean.class, jsonValue);
      assertEquals(1, o.getB());
      assertEquals(2, o.getS());
View Full Code Here


      jv.writeTo(jsonWriter);
      jsonWriter.flush();
      jsonWriter.close();

      ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
      JsonParser jsonParser = new JsonParserImpl();
      JsonHandler jsonHandler = new JsonDefaultHandler();

      jsonParser.parse(in, jsonHandler);
      JsonValue jsonValue = jsonHandler.getJsonObject();
      Book newBook = ObjectBuilder.createObject(Book.class, jsonValue);
      assertEquals(author, newBook.getAuthor());
      assertEquals(title, newBook.getTitle());
      assertEquals(pages, newBook.getPages());
View Full Code Here

   }

   public void testArrayString() throws Exception
   {
      String jsonString = "[\"JUnit in Action\",\"Advanced JavaScript\",\"Beginning C# 2008\"]";
      JsonParser jsonParser = new JsonParserImpl();

      JsonDefaultHandler handler = new JsonDefaultHandler();
      jsonParser.parse(new InputStreamReader(new ByteArrayInputStream(jsonString.getBytes())), handler);
      JsonValue jsonValue = handler.getJsonObject();

      assertTrue(jsonValue.isArray());
      Set<String> s = new HashSet<String>();
      for (Iterator<JsonValue> elements = jsonValue.getElements(); elements.hasNext();)
View Full Code Here

   public void testArrayLong() throws Exception
   {
      String jsonString = "[1, 0xAA, 077, 123, 32765, 77787, 123456789, 0x123456, 0123456, -2387648, -123456789]";

      JsonParser jsonParser = new JsonParserImpl();
      JsonDefaultHandler handler = new JsonDefaultHandler();
      jsonParser.parse(new InputStreamReader(new ByteArrayInputStream(jsonString.getBytes())), handler);
      JsonValue jsonValue = handler.getJsonObject();

      assertTrue(jsonValue.isArray());
      int i = 0;
      for (Iterator<JsonValue> elements = jsonValue.getElements(); elements.hasNext(); i++)
View Full Code Here

         "[1.0, 0.0006382746, 111111.2222222, 9999999999999.9999999999999,"
            + "9827394873249.8, 1.23456789E8, 123456.789E8, 3215478352478651238.0,"
            + "982.8, 0.00000000000023456789E8, 1.789E8, 0.0000000000000000000321547835247865123,"
            + "982.8, -0.00000000000023456789E8, -1.789E-8, -0.0000000000000000000321547835247865123]";

      JsonParser jsonParser = new JsonParserImpl();
      JsonDefaultHandler handler = new JsonDefaultHandler();
      jsonParser.parse(new InputStreamReader(new ByteArrayInputStream(jsonString.getBytes())), handler);
      JsonValue jsonValue = handler.getJsonObject();

      assertTrue(jsonValue.isArray());
      int i = 0;
      for (Iterator<JsonValue> elements = jsonValue.getElements(); elements.hasNext(); i++)
View Full Code Here

   public void testArrayMixed() throws Exception
   {
      String jsonString = "[1.0, \"to be or not to be\", 111, true, {\"object\":{\"foo\":\"bar\"}}]";

      JsonParser jsonParser = new JsonParserImpl();
      JsonDefaultHandler handler = new JsonDefaultHandler();
      jsonParser.parse(new InputStreamReader(new ByteArrayInputStream(jsonString.getBytes())), handler);
      JsonValue jsonValue = handler.getJsonObject();

      assertTrue(jsonValue.isArray());
      ArrayValue exp = new ArrayValue();
      exp.addElement(new DoubleValue(1.0D));
View Full Code Here

   public void testObject() throws Exception
   {
      String jsonString =
         "{\"foo\":\"bar\", \"book\":{\"author\":\"Christian Gross\",\"title\":\"Beginning C# 2008\"}}";

      JsonParser jsonParser = new JsonParserImpl();
      JsonDefaultHandler handler = new JsonDefaultHandler();
      jsonParser.parse(new InputStreamReader(new ByteArrayInputStream(jsonString.getBytes())), handler);
      JsonValue jsonValue = handler.getJsonObject();

      assertTrue(jsonValue.isObject());
      JsonValue sValue = jsonValue.getElement("foo");
      assertTrue(sValue.isString());
View Full Code Here

   public void testMultiDimensionArray() throws Exception
   {
      String jsonString = "[\"foo0\", [\"foo1\", \"bar1\", [\"foo2\", \"bar2\"]], \"bar0\"]";

      JsonParser jsonParser = new JsonParserImpl();
      JsonDefaultHandler handler = new JsonDefaultHandler();
      jsonParser.parse(new InputStreamReader(new ByteArrayInputStream(jsonString.getBytes())), handler);
      JsonValue jsonValue = handler.getJsonObject();
      //System.out.println(jsonValue);

      ArrayValue exp = new ArrayValue();
      exp.addElement(new StringValue("foo0"));
View Full Code Here

TOP

Related Classes of org.exoplatform.ws.frameworks.json.JsonParser

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.