Package com.google.gson

Examples of com.google.gson.JsonParser


    assertEquals(EventType.BLIP_SUBMITTED, calledEvents.get(0));
    assertEquals(EventType.DOCUMENT_CHANGED, calledEvents.get(1));
    assertEquals(EventType.WAVELET_TAGS_CHANGED, calledEvents.get(2));

    // Assert that the outgoing operation bundle contains robot.notify() op.
    JsonParser jsonParser = new JsonParser();
    JsonArray ops = jsonParser.parse(mockWriter.getString()).getAsJsonArray();
    assertEquals(1, ops.size());

    JsonObject op = ops.get(0).getAsJsonObject();
    assertEquals(OperationType.ROBOT_NOTIFY_CAPABILITIES_HASH.method(),
        op.get(RequestProperty.METHOD.key()).getAsString());
View Full Code Here


*/
public class JsonRpcResponseGsonAdaptorTest extends TestCase {

  public void testDeserializeJsonRpcErrorResponse() throws Exception {
    String response = "{'id':'op1','error':{'message':'Not authorized!'}}";
    JsonElement jsonElement = new JsonParser().parse(response);

    JsonRpcResponseGsonAdaptor adaptor = new JsonRpcResponseGsonAdaptor();
    JsonRpcResponse result = adaptor.deserialize(jsonElement, null, null);
    assertTrue(result.isError());
    assertEquals("op1", result.getId());
View Full Code Here

    assertEquals("Not authorized!", result.getErrorMessage());
  }

  public void testDeserializeJsonRpcResponse() throws Exception {
    String response = "{'id':'op1','data':{'newBlipId':'blip1','unknown':'value'}}";
    JsonElement jsonElement = new JsonParser().parse(response);

    JsonDeserializationContext mockContext = mock(JsonDeserializationContext.class);
    when(mockContext.deserialize(any(JsonElement.class), eq(String.class))).thenAnswer(
        new Answer<String>() {
          public String answer(InvocationOnMock invocation) {
View Full Code Here

public class OperationRequestGsonAdaptorTest extends TestCase {

  public void testDeserialize() throws Exception {
    String operation = "{'id':'op1','method':'wavelet.setTitle','params':{" +
        "'waveId':'1','waveletId':'2','waveletTitle':'Title','unknown':'value'}}";
    JsonElement jsonElement = new JsonParser().parse(operation);

    JsonDeserializationContext mockContext = mock(JsonDeserializationContext.class);
    when(mockContext.deserialize(any(JsonElement.class), eq(String.class))).thenAnswer(
        new Answer<String>() {
          public String answer(InvocationOnMock invocation) {
View Full Code Here

    assertEquals(intId, deserialized.getIntId());
    assertEquals(fooString, deserialized.getFooStrings().get(0));
    assertEquals(ComplicatedDto.TYPE, deserialized.getType());

    // Pull it out using the DTO's deserializer.
    JsonElement jsonElement = new JsonParser().parse(serialized);
    ComplicatedDtoImpl deserialized2 = ComplicatedDtoImpl.fromJsonElement(jsonElement);
    assertEquals(intId, deserialized2.getIntId());
    assertEquals(fooString, deserialized2.getFooStrings().get(0));
    assertEquals(ComplicatedDto.TYPE, deserialized2.getType());
View Full Code Here

    Type type,
    JsonSerializationContext jsonSerializationContext
  ) {
    Gson gson = new Gson();
    String s = gson.toJson(object);
    JsonParser parser = new JsonParser();
    JsonObject o = (JsonObject)parser.parse(s);
    o.getAsJsonObject().addProperty(
      CLASS_META_KEY,
      object.getClass().getCanonicalName()
    );
    return o;
View Full Code Here

    * @see RecordedRequest
    */
   public void assertRequest(RecordedRequest request, String method, String path, String resourceLocation) {
      assertRequest(request, method, path);
      assertContentTypeIsJSON(request);
      JsonParser parser = new JsonParser();
      JsonElement requestJson = null// to be compared
      JsonElement resourceJson;        // to be compared
      try {
         requestJson = parser.parse(new String(request.getBody(), "UTF-8"));
      } catch (Exception e) {
         Throwables.propagate(e);
      }
      resourceJson = parser.parse(stringFromResource(resourceLocation));
      assertEquals(requestJson, resourceJson); // Compare as JSON
   }
View Full Code Here

        JsonObject req = null;
        try {
            String requestData = transport.readRequest();
            LOG.debug("JSON-RPC >>  {}", requestData);
            JsonParser parser = new JsonParser();
            req = (JsonObject) parser.parse(new StringReader(requestData));
        } catch (Throwable t) {
            errorCode = JsonRpcErrorCodes.PARSE_ERROR_CODE;
            errorMessage = "unable to parse json-rpc request";
            errorData = getStackTrace(t);
View Full Code Here

        JsonObject req = null;
        try {
            String requestData = transport.readRequest();
            LOG.debug("JSON-RPC >>  {}", requestData);
            JsonParser parser = new JsonParser();
            req = (JsonObject) parser.parse(new StringReader(requestData));
        } catch (Throwable t) {
            errorCode = JsonRpcErrorCodes.PARSE_ERROR_CODE;
            errorMessage = "unable to parse json-rpc request";
            errorData = getStackTrace(t);
View Full Code Here

        } catch (Exception e) {
            throw new JsonRpcClientException("unable to get data from transport", e);
        }
        LOG.debug("JSON-RPC <<  {}", responseData);

        JsonParser parser = new JsonParser();
        JsonObject resp = (JsonObject) parser.parse(new StringReader(responseData));

        JsonElement result = resp.get("result");
        JsonElement error = resp.get("error");

        if (error != null && !error.isJsonNull()) {
View Full Code Here

TOP

Related Classes of com.google.gson.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.