Example usage for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES

List of usage examples for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES

Introduction

In this page you can find the example usage for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES.

Prototype

FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES

To view the source code for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES.

Click Source Link

Document

Using this naming policy with Gson will modify the Java Field name from its camel cased form to a lower case field name where each word is separated by an underscore (_).

Usage

From source file:com.google.maps.ApiContext.java

License:Open Source License

private <T, R extends ApiResponse<T>> PendingResult<T> postWithBody(Class<R> clazz, String path,
        String encodedPath, RequestBody body) {
    checkContext();/*from   w ww . ja v  a  2  s.  com*/

    StringBuilder url = new StringBuilder(path);
    if (clientId != null) {
        url.append("?client=").append(clientId);
    } else {
        url.append("?key=").append(apiKey);
    }
    url.append(encodedPath);

    if (clientId != null) {
        try {
            String signature = urlSigner.getSignature(url.toString());
            url.append("&signature=").append(signature);
        } catch (Exception e) {
            return new ExceptionResult<T>(e);
        }
    }

    Request req = new Request.Builder().post(body).header("User-Agent", USER_AGENT).url(host + url).build();

    log.log(Level.INFO, "Request: {0}", host + url);

    return new OkHttpPendingResult<T, R>(req, client, clazz, FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES,
            errorTimeout);
}

From source file:com.google.maps.GeoApiContext.java

License:Open Source License

<T, R extends ApiResponse<T>> PendingResult<T> get(Class<R> clazz, String path, Map<String, String> params) {
    StringBuilder query = new StringBuilder();

    for (Map.Entry<String, String> param : params.entrySet()) {
        query.append('&').append(param.getKey()).append("=");
        try {/*from   w  w  w.j  a v  a  2  s  .  c o  m*/
            query.append(URLEncoder.encode(param.getValue(), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            return new ExceptionResult<T>(e);
        }
    }
    return getWithPath(clazz, FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES, path, query.toString());
}

From source file:com.google.maps.GeoApiContext.java

License:Open Source License

<T, R extends ApiResponse<T>> PendingResult<T> get(Class<R> clazz, String path, String... params) {
    return get(clazz, FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES, path, params);
}

From source file:com.googleapis.maps.services.impl.BaseGoogleMapsApiQuery.java

License:Apache License

/**
 * Gets the gson builder./*from  w  w w  .j a  v a  2 s  .  c  o m*/
 * 
 * @return the gson builder
 */
protected GsonBuilder getGsonBuilder() {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat(ApplicationConstants.RFC822DATEFORMAT);
    builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    builder.registerTypeAdapter(LocationType.class, new JsonDeserializer<LocationType>() {
        @Override
        public LocationType deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return LocationType.fromValue(arg0.getAsString());
        }
    });
    builder.registerTypeAdapter(AddressComponentType.class, new JsonDeserializer<AddressComponentType>() {
        @Override
        public AddressComponentType deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return AddressComponentType.fromValue(arg0.getAsString());
        }
    });
    //      builder.registerTypeAdapter(TravelMode.class, new JsonDeserializer<TravelMode>() {
    //         @Override
    //         public TravelMode deserialize(JsonElement arg0, Type arg1,
    //               JsonDeserializationContext arg2) throws JsonParseException {
    //            return TravelMode.fromValue(arg0.getAsString());
    //         }
    //      });

    return builder;
}

From source file:com.googlesource.gerrit.plugins.github.oauth.GsonProvider.java

License:Apache License

@Override
public Gson get() {
    return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
}

From source file:com.googlesource.gerrit.plugins.lfs.LfsGson.java

License:Apache License

LfsGson() {
    this.gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .disableHtmlEscaping().create();
}

From source file:com.hackerati.android.user_sdk.gson.HGsonBuilder.java

License:Open Source License

public static final Gson create() {
    final GsonBuilder builder = new GsonBuilder();
    builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    return builder.create();
}

From source file:com.hacksurfer.api.client.RunIndustryRiskScoreExample.java

License:Open Source License

public static void main(String args[]) throws Exception {

    LOG.info("Running example HTTP GET against HackSurfer Industry Risk Scores /yesterday resource.");

    SimpleRestClient client = new SimpleRestClient();
    String response = client.httpGet(API_BASE_URL, IRS_YESTERDAY_RESOURCE_PATH);

    // print response
    LOG.info("Response from /yesterday resource : {}", response);

    // do something useful with it
    GsonBuilder gb = new GsonBuilder();
    gb.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    Gson gson = gb.create();/*  w  ww  .j a va 2  s .  c  om*/

    List<IndustryRiskScore> scores = gson.fromJson(response, new TypeToken<List<IndustryRiskScore>>() {
    }.getType());
    LOG.info("Found {} industry risk scores from yesterday.", scores.size());
    for (IndustryRiskScore irs : scores) {
        StringBuilder sb = new StringBuilder();
        sb.append(System.lineSeparator());
        sb.append("Industry : ");
        sb.append(irs.getIndustryDescription());
        sb.append(System.lineSeparator());
        sb.append("  id : ");
        sb.append(irs.getIndustryId());
        sb.append(System.lineSeparator());
        sb.append("  risk : ");
        sb.append(irs.getIndustryGravity());
        sb.append(System.lineSeparator());
        sb.append("  gravity : ");
        sb.append(irs.getIndustryRisk());
        sb.append(System.lineSeparator());
        sb.append("  momentum : ");
        sb.append(irs.getIndustryMomentum());
        sb.append(System.lineSeparator());

        System.out.println(sb.toString());
    }

    LOG.info("Well that was fun!");

}

From source file:com.ibm.og.cli.ObjectGenerator.java

License:Open Source License

public static Gson createGson() {
    return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory())
            // SizeUnit and TimeUnit TypeAdapters must be registered after
            // CaseInsensitiveEnumTypeAdapterFactory in order to override the registration
            .registerTypeHierarchyAdapter(SizeUnit.class, new SizeUnitTypeAdapter().nullSafe())
            .registerTypeHierarchyAdapter(TimeUnit.class, new TimeUnitTypeAdapter().nullSafe())
            .registerTypeAdapterFactory(new OperationConfigTypeAdapterFactory())
            .registerTypeAdapterFactory(new SelectionConfigTypeAdapterFactory())
            .registerTypeAdapterFactory(new ChoiceConfigTypeAdapterFactory())
            .registerTypeAdapterFactory(new FilesizeConfigTypeAdapterFactory())
            .registerTypeAdapterFactory(new ContainerConfigTypeAdapterFactory()).setPrettyPrinting().create();
}

From source file:com.ibm.og.cli.ObjectGenerator.java

License:Open Source License

public static Gson createIntervalGson() {
    return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory())
            // SizeUnit and TimeUnit TypeAdapters must be registered after
            // CaseInsensitiveEnumTypeAdapterFactory in order to override the registration
            .registerTypeHierarchyAdapter(SizeUnit.class, new SizeUnitTypeAdapter().nullSafe())
            .registerTypeHierarchyAdapter(TimeUnit.class, new TimeUnitTypeAdapter().nullSafe())
            .registerTypeAdapterFactory(new OperationConfigTypeAdapterFactory())
            .registerTypeAdapterFactory(new SelectionConfigTypeAdapterFactory())
            .registerTypeAdapterFactory(new ChoiceConfigTypeAdapterFactory())
            .registerTypeAdapterFactory(new FilesizeConfigTypeAdapterFactory())
            .registerTypeAdapterFactory(new ContainerConfigTypeAdapterFactory()).create();
}