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.twitter.sdk.android.core.internal.scribe.DefaultScribeClient.java

License:Apache License

private static Gson getGson() {
    return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
}

From source file:com.urswolfer.gerrit.client.rest.gson.GsonFactory.java

License:Apache License

public static Gson create() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Date.class, new DateDeserializer());
    builder.registerTypeAdapter(Date.class, new DateSerializer());
    builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    return builder.create();
}

From source file:com.vimeo.networking.model.VimeoAccount.java

License:Open Source License

public VimeoAccount(String accessToken, String tokenType, String scope, String userJSON) {
    if (accessToken == null || accessToken.isEmpty() || tokenType == null || tokenType.isEmpty()
            || scope == null || scope.isEmpty()) {
        throw new AssertionError("Account can only be created with token, tokenType, scope");
    }//w  ww.  ja v  a  2s. c om

    this.accessToken = accessToken;
    this.tokenType = tokenType;
    this.scope = scope;

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

    this.user = gson.fromJson(userJSON, User.class);
}

From source file:com.vimeo.networking.model.VimeoAccount.java

License:Open Source License

@Nullable
public String getUserJSON() // For AccountManager.userData [AH]
{
    if (this.user == null) {
        return null;
    }//from   w w  w  . j  av a 2  s . co m

    if (this.userJSON != null) {
        return this.userJSON;
    }

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

    this.userJSON = gson.toJson(this.user);

    return this.userJSON;
}

From source file:com.vimeo.networking.utils.VimeoNetworkUtil.java

License:Open Source License

/**
 * Static helper method that automatically applies the VimeoClient Gson preferences
 * </p>//from   w w w . j  a  v a 2 s  .  c om
 * This includes formatting for dates as well as a LOWER_CASE_WITH_UNDERSCORES field naming policy
 * @return GsonBuilder that can be built upon and then created
 */
public static GsonBuilder getGsonBuilder() {
    // Example date: "2015-05-21T14:24:03+00:00"
    return new GsonBuilder().registerTypeAdapterFactory(new Stag.Factory())
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
}

From source file:com.vimeo.turnstile.database.TaskDatabase.java

License:Open Source License

public TaskDatabase(Context context, String name, Class<T> taskClass) {
    SqlProperty[] PROPERTIES = { ID_COLUMN, STATE_COLUMN, TASK_COLUMN, CREATE_AT_COLUMN };
    mHelper = new DbOpenHelper(context, name, DATABASE_VERSION, ID_COLUMN, PROPERTIES);
    mDatabase = mHelper.getWritableDatabase();
    mSqlHelper = new SqlHelper(mDatabase, mHelper.getTableName(), ID_COLUMN.columnName, PROPERTIES);

    mTaskClass = taskClass;/*  w  w  w  .j a  v  a2s.  c o  m*/
    mGsonSerializer = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .create();
}

From source file:com.xebia.xoverflow.server.service.DaggerModule.java

License:Apache License

@Provides
@Singleton/*from  w w  w  .  j av a  2s  .  co  m*/
Gson provideGson() {
    return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .registerTypeAdapter(Date.class, new DateToTimestampAdapter()).create();
}

From source file:com.yaesta.integration.datil.service.DatilService.java

private FacturaRespuestaSRI invoice(FacturaSRI input, OrderComplete orderComplete) {
    FacturaRespuestaSRI response = new FacturaRespuestaSRI();

    String restUrl = datilWebServiceUrl + "/invoices/issue";

    systemOut.println("URL" + restUrl);

    client = ClientBuilder.newClient();//w w w  .  j a  v  a  2  s.  c o  m
    target = client.target(restUrl);

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

    String json = gson.toJson(input);

    systemOut.println("Factura:" + json);

    if (datilDoInvoice.equals("Y")) {
        String responseJson = target.request(MediaType.APPLICATION_JSON_TYPE).headers(buildHeaders())
                .post(Entity.json(json), String.class);
        systemOut.println("==>>" + responseJson);

        YaEstaLog yaestaLog = new YaEstaLog();
        yaestaLog.setLogDate(new Date());
        yaestaLog.setXmlInfo(responseJson);
        yaestaLog.setProcessName("INVOICE");
        yaestaLog.setTextinfo(orderComplete.getOrderId());
        logService.save(yaestaLog);

        response = gson.fromJson(responseJson, FacturaRespuestaSRI.class);

    }
    return response;
}

From source file:com.yaesta.integration.datil.service.DatilService.java

private GuiaRemisionRespuesta waybill(GuiaRemision input) {
    GuiaRemisionRespuesta response = new GuiaRemisionRespuesta();

    String restUrl = datilWebServiceUrl + "/waybills/issue";

    systemOut.println("URL" + restUrl);

    client = ClientBuilder.newClient();/*from   w  ww  . jav  a  2 s  .co  m*/
    target = client.target(restUrl);

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

    String json = gson.toJson(input);

    systemOut.println("Guia de Remision:" + json);
    String responseJson = target.request(MediaType.APPLICATION_JSON_TYPE).headers(buildHeaders())
            .post(Entity.json(json), String.class);
    systemOut.println("==>>" + responseJson);

    response = gson.fromJson(responseJson, GuiaRemisionRespuesta.class);
    return response;
}

From source file:com.yaesta.integration.datil.service.DatilService.java

private NotaCreditoRespuesta creditNote(NotaCredito input, OrderComplete orderComplete) {
    NotaCreditoRespuesta response = new NotaCreditoRespuesta();

    String restUrl = datilWebServiceUrl + "/credit-notes/issue";

    client = ClientBuilder.newClient();//from  ww  w  .  j a  v  a  2s  . c o m
    target = client.target(restUrl);

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

    String json = gson.toJson(input);

    systemOut.println("Nota de Credito:" + json);
    try {

        String responseJson = target.request(MediaType.APPLICATION_JSON_TYPE).headers(buildHeaders())
                .post(Entity.json(json), String.class);

        systemOut.println("1==>>" + responseJson);

        YaEstaLog yaestaLog = new YaEstaLog();
        yaestaLog.setLogDate(new Date());
        yaestaLog.setXmlInfo(responseJson);
        yaestaLog.setProcessName("INVOICE");
        yaestaLog.setTextinfo(orderComplete.getOrderId());
        logService.save(yaestaLog);

        response = gson.fromJson(responseJson, NotaCreditoRespuesta.class);
    } catch (Exception e) {
        systemOut.println("2==>>" + e.getMessage());
        String responseJson = target.request(MediaType.APPLICATION_JSON_TYPE).headers(buildHeaders())
                .post(Entity.json(json), String.class);
        ResponseError responseError = gson.fromJson(responseJson, ResponseError.class);
        response.setErrors(responseError.getErrors());
    }

    return response;
}