Example usage for com.google.gson GsonBuilder GsonBuilder

List of usage examples for com.google.gson GsonBuilder GsonBuilder

Introduction

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

Prototype

public GsonBuilder() 

Source Link

Document

Creates a GsonBuilder instance that can be used to build Gson with various configuration settings.

Usage

From source file:cl.niclabs.cb.common.MethodParser.java

License:Open Source License

public static Gson makeGson(MethodFactory factory) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(Method.class, new MethodParser(factory));
    return gsonBuilder.create();
}

From source file:cl.niclabs.tscrypto.common.utils.Util.java

License:Open Source License

public static Gson GsonFactory(boolean pretty) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    if (pretty)//from   www. j a v  a  2 s  .  com
        gsonBuilder.setPrettyPrinting();
    gsonBuilder.registerTypeAdapter(BigInteger.class, new BigIntegerBase64TypeAdapter());
    gsonBuilder.registerTypeAdapter(TSMessage.class, new TSMessageParser());
    return gsonBuilder.create();
}

From source file:classes.analysis.Analysis.java

License:Open Source License

/**
 * This static function returns a new object using the data contained in the
 * given JSON object (as String)./*from w w  w  .  java 2 s. com*/
 *
 * @param jsonString the JSON object
 * @return the new Object.
 */
public static Analysis fromJSON(JsonElement jsonString) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(NonProcessedData.class, getNonProcessedDataDeserializerInstance());
    gsonBuilder.registerTypeAdapter(ProcessedData.class, getProcessedDataDeserializerInstance());
    Gson gson = gsonBuilder.create();

    Analysis analysis = gson.fromJson(jsonString, Analysis.class);

    //FINALLY, WE HAVE TO ORDER THE NON PROCESSED DATA BY STEP NUMBER
    Arrays.sort(analysis.getNonProcessedData());

    return analysis;
}

From source file:classes.analysis.non_processed_data.RAWdata.java

License:Open Source License

/**
 * This static function returns a new object using the data contained in the
 * given JSON object (as String)./*  ww w  .jav a  2 s  .com*/
 *
 * @param jsonString the JSON object
 * @return the new Object.
 */
public static RAWdata fromJSON(String jsonString) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(ExtractionMethod.class, getExtractionMethodDeserializerInstance());
    Gson gson = gsonBuilder.create();
    RAWdata step = gson.fromJson(jsonString, RAWdata.class);

    if (step.extractionMethod != null) {
        step.extractionMethod.setRawdataID(step.getStepID());
    }

    return step;
}

From source file:classes.analysis.non_processed_data.raw_data.ExtractionMethods.MassSpectrometry.java

License:Open Source License

/**
 * This static function returns a new object using the data contained in the
 * given JSON object (as String)./* ww  w  .j  a va 2  s  .  c  om*/
 *
 * @param jsonString the JSON object
 * @return the new Object.
 */
public static MassSpectrometry fromJSON(String jsonString) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(SeparationMethod.class, getSeparationMethodDeserializerInstance());
    Gson gson = gsonBuilder.create();
    MassSpectrometry massSpectrometry = gson.fromJson(jsonString, MassSpectrometry.class);

    if (massSpectrometry.getSeparationMethod() != null) {
        massSpectrometry
                .setSeparationMethodType(massSpectrometry.getSeparationMethod().getSeparationMethodType());
    }

    return massSpectrometry;
}

From source file:classes.analysis.non_processed_data.raw_data.ExtractionMethods.NuclearMagneticResonance.java

License:Open Source License

/**
 * This static function returns a new object using the data contained in the
 * given JSON object (as String)./*ww w  .  j a va  2 s .c o m*/
 *
 * @param jsonString the JSON object
 * @return the new Object.
 */
public static NuclearMagneticResonance fromJSON(String jsonString) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(SeparationMethod.class, getSeparationMethodDeserializerInstance());
    Gson gson = gsonBuilder.create();
    NuclearMagneticResonance nuclearMagneticResonance = gson.fromJson(jsonString,
            NuclearMagneticResonance.class);

    if (nuclearMagneticResonance.getSeparationMethod() != null) {
        nuclearMagneticResonance.setSeparationMethodType(
                nuclearMagneticResonance.getSeparationMethod().getSeparationMethodType());
    }

    return nuclearMagneticResonance;
}

From source file:click.kobaken.rxirohaandroid.di.IrohaModule.java

License:Open Source License

private Gson createGson() {
    return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .registerTypeAdapter(Date.class, new DateTypeAdapter()).create();
}

From source file:client.communication.ClientCommunicator.java

/**
 * Default Constructor. Used only to create the singleton.
 *///from ww w  .ja  v  a 2 s. c o  m
private ClientCommunicator() {
    model = new GsonBuilder().create();
    cookies = new HashMap<>();
}

From source file:client.model.Application.java

public static String toJson(List<Application> list) {
    Gson gson = new GsonBuilder().setDateFormat(Utility.DATE_FORMAT_STRING_SHORT).create();
    String gsonString = gson.toJson(list, new TypeToken<List<Application>>() {
    }.getType());/*from   w  w  w .  j ava2 s .com*/
    return gsonString;
}

From source file:client.model.Application.java

public static List<Application> fromJson(String json) throws JsonSyntaxException {
    Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new Utility.JsonDateDeserializer()).create();
    List<Application> list = gson.fromJson(json, new TypeToken<List<Application>>() {
    }.getType());//from w  w w.j a  va  2  s .  co  m
    return list;
}