Example usage for com.google.gson FieldNamingPolicy IDENTITY

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

Introduction

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

Prototype

FieldNamingPolicy IDENTITY

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

Click Source Link

Document

Using this naming policy with Gson will ensure that the field name is unchanged.

Usage

From source file:rest.NewUser.java

public NewUser() {
    gson = new GsonBuilder().setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create();
}

From source file:rest.ReservationApi.java

/**
 * Creates a new instance of ReservationApi
 */
public ReservationApi() {
    gson = new GsonBuilder().setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create();
}

From source file:rest.RestServicePerson.java

public RestServicePerson() {
    gson = new GsonBuilder().setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create();
}

From source file:rest.util.JsonConverter.java

public static String DailyRAteJsonObj() {

    Gson gson = new GsonBuilder().setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create();
    EntityManager em = Persistence.createEntityManagerFactory(DeploymentConfiguration.PU_NAME)
            .createEntityManager();//from  w  w w.  jav  a2 s.co  m
    List<DailyRate> dailyrates = em.createQuery("select t from DailyRate t").getResultList();
    //        List<DailyRate> dailyrates = em.createQuery("select t from DailyRate t", DailyRate.class).getResultList();

    JsonArray jsonArray = new JsonArray();
    for (DailyRate p : dailyrates) {
        JsonObject json = new JsonObject();

        json.addProperty("date", p.getDate().toString());
        json.addProperty("rate", p.getRate());

        if (p.getCurrencycode() != null) {

            json.addProperty("currencyCode", p.getCurrencycode().getCode());
            json.addProperty("description", p.getCurrencycode().getDescription());

        }
        jsonArray.add(json);
    }

    return gson.toJson(jsonArray);
}

From source file:syncthing.api.GsonModule.java

License:Mozilla Public License

@Provides
@Singleton/*from w w w. ja v  a  2s. com*/
public Gson provideGson() {
    return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY)
            .registerTypeAdapter(DateTime.class, new DateTimeTypeConverter())
            .registerTypeAdapter(Event.class, new EventDeserializer())
            .registerTypeAdapter(Versioning.class, new VersioningTypeConverter()).create();
}

From source file:ua.pp.msk.cliqr.job.JobRunInit.java

License:Apache License

public String toJson() {
    GsonBuilder gb = new GsonBuilder();
    gb.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY);
    gb.setPrettyPrinting();/*from  ww w  .  j  a  v a2  s. c  o m*/
    Gson gson = gb.create();
    String toJson = gson.toJson(this);
    return toJson;
}