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:co.cask.cdap.passport.meta.Account.java

License:Apache License

/**
 * Deserialize Account from jsonString./*from w w w. jav a 2 s .c  o  m*/
 * @param jsonString json string containing account info
 * @return {@code Account}
 */
public static Account fromString(String jsonString) {
    Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    return gson.fromJson(jsonString, Account.class);
}

From source file:co.cask.cdap.passport.meta.Account.java

License:Apache License

/**
 * Serialize account into json string. The field names will be lowercase with underscores where captialized.
 * @return Json serialized String representing account
 *///from   w  w w. j a va2 s. c  om
@Override
public String toString() {
    Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    return gson.toJson(this);

}

From source file:com.addhen.voto.sdk.BaseApiBuilder.java

License:Apache License

private void initializeGson() {
    GsonBuilder builder = new GsonBuilder();
    builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    builder.registerTypeAdapter(Date.class, new DateDeserializer());
    mGson = builder.create();/*w ww.  j  a v  a  2s  .com*/
}

From source file:com.addhen.voto.sdk.test.BaseTestCase.java

License:Apache License

@Before
public void setUp() throws Exception {
    mGson = new GsonBuilder().registerTypeAdapter(Date.class, new DateDeserializer())
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    mGsonDeserializer = new GsonDeserializer(mGson);
}

From source file:com.ahmadrosid.lib.baseapp.core.BasePresenter.java

License:Apache License

public BasePresenter(T mvpView) {
    this.mvpView = mvpView;
    gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .setPrettyPrinting().registerTypeAdapter(Date.class, new DateTypeAdapter()).create();
}

From source file:com.amgems.uwschedule.api.local.WebService.java

License:Open Source License

public static void init() {
    Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .excludeFieldsWithoutExposeAnnotation().create();
    RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(WEB_SERVICE_URL)
            .setConverter(new GsonConverter(gson)).build();
    request = restAdapter.create(ScheduleRequest.class);
}

From source file:com.android.example.leanback.fastlane.LeanbackBrowseFragment.java

License:Open Source License

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .registerTypeAdapter(Date.class, new DateTypeAdapter()).create();

    RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("https://hub.gdgx.io/api/v1/")
            .setConverter(new GsonConverter(gson)).build();

    HubApiService hubApiService = restAdapter.create(HubApiService.class);
    hubApiService.getAllGdes(this);
}

From source file:com.bing.maps.rest.services.impl.BaseBingMapsApiQuery.java

License:Apache License

/**
 * Gets the gson builder.//from  w w  w .j  av  a 2  s .  com
 * 
 * @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.brunomcustodio.dojo.keycloak.auth.AuthServiceEndpointsImpl.java

License:Apache License

public AuthServiceEndpointsImpl() throws ConfigurationException {
    Configuration config = new PropertiesConfiguration("auth.properties");

    bauth = BasicAuth.createHeader(config.getString("keycloak.client"), config.getString("keycloak.secret"));
    realm = config.getString("keycloak.realm");

    Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();

    RestAdapter.Builder builder = new RestAdapter.Builder();
    builder.setConverter(new GsonConverter(gson));
    builder.setEndpoint(config.getString("keycloak.root"));
    RestAdapter ra = builder.build();//from ww  w. ja  va 2  s  . c  o  m

    client = ra.create(KeycloakClient.class);
}

From source file:com.btkelly.gnag.api.GitHubApi.java

License:Apache License

private GitHubApi(final GnagPluginExtension gnagPluginExtension) {
    this.gnagPluginExtension = gnagPluginExtension;

    OkHttpClient okHttpClient = new OkHttpClient();
    okHttpClient.interceptors().add(new AuthInterceptor(gnagPluginExtension));
    okHttpClient.interceptors().add(new LoggingInterceptor());

    String baseUrl = "https://api.github.com/repos/" + gnagPluginExtension.getGitHubRepoName() + "/";

    Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();

    GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);

    Retrofit retrofit = new Retrofit.Builder().baseUrl(baseUrl).client(okHttpClient)
            .addConverterFactory(gsonConverterFactory).build();

    gitHubApiClient = retrofit.create(GitHubApiClient.class);
}