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:edu.mit.media.funf.config.DefaultRuntimeTypeAdapterFactory.java

License:Open Source License

/**
 * @param context//  w  ww  .j  a  v a  2s  .co m
 * @param baseClass  
 * @param defaultClass  Setting this to null will cause a ParseException if the runtime type information is incorrect or unavailable.
 */
public DefaultRuntimeTypeAdapterFactory(Context context, Class<E> baseClass, Class<? extends E> defaultClass,
        TypeAdapterFactory delegateFactory) {
    assert context != null && baseClass != null;
    if (defaultClass != null && !isInstantiable(defaultClass)) {
        throw new RuntimeException("Default class does not have a default contructor.");
    }
    this.context = context;
    this.baseClass = baseClass;
    this.defaultClass = defaultClass;
    if (delegateFactory == null) {
        this.delegateFactory = new ReflectiveTypeAdapterFactory(
                new ConstructorConstructor(Collections.<Type, InstanceCreator<?>>emptyMap()),
                FieldNamingPolicy.IDENTITY, Excluder.DEFAULT);
    } else {
        this.delegateFactory = delegateFactory;
    }
}

From source file:fr.ycoupe.pronobike.activities.RulesActivity.java

private void loadRules() {
    Logger.log(Logger.Level.DEBUG, TAG, "loadRules");

    final String raw = readRulesFile();
    final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create();
    final RulesData data = gson.fromJson(raw, RulesData.class);

    for (final RulesData.Rule r : data.rules) {
        addRule(r);/*from w ww.jav a  2s .  c om*/
    }
}

From source file:hu.unideb.inf.battleship.model.GameService.java

/**
 * Loads the saved game if theres any, else it creates a new game.
 * //w w w . j  a  v a  2  s. c o  m
 * @param fileName the name of the saved game.
 * @return The saved game or a new game.
 */
public Game loadGame(String fileName) {

    Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create();
    try {
        logger.info("Loading Game");
        return gson.fromJson(new InputStreamReader(new FileInputStream(fileName)), Game.class);
    } catch (IOException ex) {
        logger.error("Exception during loading");
        logger.error(ex.getClass().getName());
        logger.info("initializing a new game instead");
        return new Game();
    }
}

From source file:main.api.MongoAPI.java

/**
 * Creates a new instance of MongoAPI//from w  w w.  j  av a  2 s .  c o  m
 */
public MongoAPI() {
    gson = new GsonBuilder().setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create();
    facade = new BookFacadeMongo();
}

From source file:main.api.MongoAPI.java

/**
 * Creates a new instance of MongoAPI that injects a BookMongoFacade.
 *
 * @param facade the facade that needs to be injected.
 *//*w  w  w. j av  a  2  s. c  o m*/
public MongoAPI(IBookFacadeMongo facade) {
    gson = new GsonBuilder().setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create();
    this.facade = facade;
}

From source file:org.akop.crosswords.model.Config.java

License:Open Source License

public static Config createFromResource(Context context, int rawResourceId) {
    Resources res = context.getResources();
    InputStream is = res.openRawResource(rawResourceId);
    StringBuilder sb = new StringBuilder();

    try {//from   ww  w  . j  a va 2s.  c om
        InputStreamReader reader;
        try {
            reader = new InputStreamReader(is, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

        int n;
        char[] buffer = new char[1024];

        try {
            while ((n = reader.read(buffer)) != -1) {
                sb.append(buffer, 0, n);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } finally {
        try {
            is.close();
        } catch (IOException e) {
        }
    }

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

    return gson.fromJson(sb.toString(), Config.class);
}

From source file:org.akop.crosswords.Storage.java

License:Open Source License

private Storage() {
    mPuzzleCache = new SparseArray<>();
    mStateCache = new SparseArray<>();

    mGson = new GsonBuilder().registerTypeAdapter(DateTime.class, new DateTimeAdapter())
            .setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create();
}

From source file:org.apache.atlas.services.AtlasPatchHandler.java

License:Apache License

public static Gson initializeGson() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(Multiplicity.class, new MultiplicityDeserializer());
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY);
    Gson gson = gsonBuilder.create();/*  w w w .j a  va2  s.c om*/

    return gson;
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.security.HopsworksRMAppSecurityActions.java

License:Apache License

public HopsworksRMAppSecurityActions() throws MalformedURLException, GeneralSecurityException {
    ACCEPTABLE_HTTP_RESPONSES.add(HttpStatus.SC_OK);
    ACCEPTABLE_HTTP_RESPONSES.add(HttpStatus.SC_NO_CONTENT);
    authHeader = new AtomicReference<>();
    GsonBuilder parserBuilder = new GsonBuilder();
    parserBuilder.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY);
    parserBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    jsonParser = parserBuilder.create();

    tokenRenewer = Executors.newSingleThreadExecutor(
            new ThreadFactoryBuilder().setNameFormat("JWT renewer thread").setDaemon(true).build());
}

From source file:org.gdg.frisbee.android.api.GroupDirectory.java

License:Apache License

public ApiRequest getEvent(String eventId, Response.Listener<EventFullDetails> successListener,
        Response.ErrorListener errorListener) {
    GsonRequest<Void, EventFullDetails> eventReq = new GsonRequest<>(Request.Method.GET,
            EVENT_DETAIL_URL + eventId, EventFullDetails.class, successListener, errorListener,
            GsonRequest.getGson(FieldNamingPolicy.IDENTITY, new ZuluDateTimeDeserializer()));
    eventReq.setRetryPolicy(new DefaultRetryPolicy(60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    return new ApiRequest(eventReq);
}