Package com.google.gson

Examples of com.google.gson.Gson


*/
public class GsonFactory
{
   public static Gson createInstance()
   {
      Gson gson = new GsonBuilder()
        .setDateFormat("yyyy-MM-dd HH:mm:ss")
        .registerTypeAdapter(java.sql.Timestamp.class, new SQLDateTypeAdapter())
        .create();
      return gson;
   }
View Full Code Here


      JSONEvent e = new JSONEvent();
      e.setHeaders(input);
      e.setBody(String.valueOf(rand.nextGaussian()).getBytes(encoding));
      events.add(e);
    }
    Gson gson = new Gson();
    String json = gson.toJson(events, listType);
    StringEntity input = new StringEntity(json);
    input.setContentType("application/json; charset=" + encoding);
    postRequest.setEntity(input);
    HttpResponse resp = httpClient.execute(postRequest);
    return new ResultWrapper(resp, events);
View Full Code Here

      }

      JsonObject ipObject = new JsonObject();

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

      return ipObject;
   }
View Full Code Here

      }

      JsonObject vlanObject = new JsonObject();

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

      return vlanObject;
   }
View Full Code Here

      if (input.getMedia() != null) {
         driveObject.addProperty("media", input.getMedia().toString());
      }

      if (input.getAffinities() != null) {
         driveObject.add("affinities", new JsonParser().parse(new Gson().toJson(input.getAffinities())));
      }

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

      if (input.getTags() != null) {
         driveObject.add("tags", new JsonParser().parse(new Gson().toJson(input.getTags())));
      }

      driveObject.addProperty("allow_multimount", input.isAllowMultimount());
      return driveObject;
   }
View Full Code Here

*/
@Test(groups = "unit")
public class BindVMSpecsToXmlPayloadTest {

   public void test() throws IOException {
      CIMOperatingSystem os = Iterables.find(new Gson().<Set<CIMOperatingSystem>> fromJson(Strings2
               .toStringAndClose(getClass()
                        .getResourceAsStream("/savvis-symphonyvpdc/predefined_operatingsystems.json")),
               new TypeLiteral<Set<CIMOperatingSystem>>() {
               }.getType()), new Predicate<CIMOperatingSystem>() {

View Full Code Here

    protected XingUser fetchUser(final Token accessToken) throws Exception {
        final OAuthRequest request = new OAuthRequest(Verb.GET, usersMeUrl);
        oAuthService.signRequest(accessToken, request);
        final Response response = request.send();
        final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
        final Users users = gson.fromJson(response.getBody(), Users.class);
        return users.getUsers().get(0);
    }
View Full Code Here

        }
        return null;
    }

    public static XingUser fromJson(final String json) {
        final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
        return gson.fromJson(json, XingUser.class);
    }
View Full Code Here

        final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
        return gson.fromJson(json, XingUser.class);
    }

    public static String hash(final String json, final String secretKey, final String hashAlgorithm) throws InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException {
        final Gson gson = new Gson();
        final List<String> list = new ArrayList<String>();
        final Map map = gson.fromJson(json, Map.class);
        join(map, list, "");
        Collections.sort(list);
        final String message = StringUtils.join(list, null);
        final byte[] result = hmac(message, secretKey, hashAlgorithm);
        return Hex.encodeHexString(result);
View Full Code Here

public class SubscriptionUtil {
 
  private static final String HMAC_SHA1 = "HmacSHA1";
   
    public static SubscriptionResponseObject[] getSubscriptionResponseData(String jsonBody) throws InstagramException {
        Gson gson = new Gson();
        SubscriptionResponseObject[] responseData;

          try {
            responseData = gson.fromJson(jsonBody, SubscriptionResponseObject[].class);
          } catch (Exception e) {
              throw new InstagramException("Error parsing json to object type ");
          }

          return responseData;
View Full Code Here

TOP

Related Classes of com.google.gson.Gson

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.