Package com.google.gson

Examples of com.google.gson.JsonParser


      if (input.getName() != null) {
         firewallObject.addProperty("name", input.getName());
      }

      if (input.getMeta() != null) {
         firewallObject.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta())));
      }

      if (input.getRules() != null) {
         JsonArray rulesArray = new JsonArray();
View Full Code Here


      metaMap.put("install_notes", "test_install_notes");

      result.addProperty("name", "test");
      result.addProperty("size", "1024000000");
      result.addProperty("media", "disk");
      result.add("affinities", new JsonParser().parse(new Gson().toJson(affinities)));
      result.add("meta", new JsonParser().parse(new Gson().toJson(metaMap)));
      result.add("tags", new JsonParser().parse(new Gson().toJson(tags)));
      result.addProperty("allow_multimount", false);

      input = new DriveInfo.Builder()
            .affinities(ImmutableList.of("ssd", "sample"))
            .allowMultimount(false)
View Full Code Here

public class MockResponseTest extends TestCase {

  private JsonParser parser;

  @Override protected void setUp() throws Exception {
    parser = new JsonParser();
  }
View Full Code Here

    EasyMock.expect(gatewayFactory.create("http://www.asdf.com", "/asdf")).andReturn(
        gateway);
    EasyMock.expect(mockFactory.create(EasyMock.isA(MockResponse.class))).andReturn(
        mock);
    control.replay();
    JsonArray jsonConfig = new JsonParser().parse(CONFIG).getAsJsonArray();
    configuration.updateConfiguration(jsonConfig);
    assertEquals(2, configuration.getMatchers().size());
    assertEquals(gateway,
        configuration.getRequestHandler(new RequestMatcher(ANY, "/asdf")));
    assertEquals(mock,
View Full Code Here

   
    @Override
    public void writeTo(List objs, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4, MultivaluedMap<String, Object> arg5, OutputStream out) throws IOException, WebApplicationException {
        JsonArray array = new JsonArray();
        for(Object obj : objs) {
            JsonParser parser = new JsonParser();
            try {
                JAXBContext context = JAXBContext.newInstance(obj.getClass());
                Marshaller marshaller = context.createMarshaller();
                StringWriter sw = new StringWriter();
                JSONJAXBContext.getJSONMarshaller(marshaller).marshallToJSON(obj, sw);
                array.add(parser.parse(sw.toString()));
            }
            catch(JAXBException e) {
                array.add(new JsonPrimitive(obj.toString()));
            }
        }
View Full Code Here

    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.method(),
        op.get(RequestProperty.METHOD.key()).getAsString());
View Full Code Here

*/
public class JsonRpcResponseGsonAdaptorRobotTest 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 OperationRequestGsonAdaptorRobotTest 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

    return writer.toString();
  }

  private <T extends Message> T fetchWaverRefAndParse(WaveRef waveref, Class<T> klass) throws Exception {
    String message = fetchWaveRef(waveref);
    JsonElement json = new JsonParser().parse(message);
    return protoSerializer.fromJson(json, klass);
  }
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.