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:ch.epfl.leb.sass.logging.internal.FluorophoreStateTransition.java

License:Open Source License

/**
 * Returns the the message as a JSON string.
 * /*from w ww. j  a  v  a2s  .c o  m*/
 * @return The properties of the fluorophore as a JSON string.
 */
@Override
public JsonElement toJson() {
    Gson gson = new GsonBuilder()
            .registerTypeAdapter(FluorophoreStateTransition.class, new FluorophoreStateTransitionSerializer())
            .create();
    return gson.toJsonTree(this);
}

From source file:ch.epfl.leb.sass.logging.internal.LaserPowerChange.java

License:Open Source License

/**
 * Returns the the message as a JSON string.
 * /*from w w w.  j  av a 2s  .  c o m*/
 * @return The properties of the fluorophore as a JSON string.
 */
@Override
public JsonElement toJson() {
    Gson gson = new GsonBuilder().registerTypeAdapter(LaserPowerChange.class, new LaserPowerChangeSerializer())
            .create();
    return gson.toJsonTree(this);
}

From source file:ch.epfl.leb.sass.models.components.internal.DefaultCamera.java

License:Open Source License

/**
 * Outputs the camera's properties as a JSON element.
 * //from  w  w w .j a  v a2 s .c  om
 * @return A JSON tree describing the camera's properties.
 */
public JsonElement toJson() {
    Gson gson = new GsonBuilder().registerTypeAdapter(DefaultCamera.class, new DefaultCameraSerializer())
            .create();
    return gson.toJsonTree(this);
}

From source file:ch.epfl.leb.sass.models.components.internal.DefaultLaser.java

License:Open Source License

/**
 * Outputs the laser's properties as a JSON element.
 * //from  w  w w.j  a v a 2 s.  com
 * @return A JSON tree describing the laser's properties.
 */
@Override
public JsonElement toJson() {
    Gson gson = new GsonBuilder().registerTypeAdapter(DefaultLaser.class, new DefaultLaserSerializer())
            .create();
    return gson.toJsonTree(this);
}

From source file:ch.epfl.leb.sass.models.components.internal.DefaultObjective.java

License:Open Source License

/**
 * Outputs the laser's properties as a JSON element.
 * // ww w . j a v  a  2 s  . c  om
 * @return A JSON tree describing the laser's properties.
 */
@Override
public JsonElement toJson() {
    Gson gson = new GsonBuilder().registerTypeAdapter(DefaultObjective.class, new DefaultObjectiveSerializer())
            .create();
    return gson.toJsonTree(this);
}

From source file:ch.epfl.leb.sass.models.components.internal.DefaultStage.java

License:Open Source License

/**
 * Outputs the laser's properties as a JSON element.
 * // ww  w  .  j a v  a  2s  .c om
 * @return A JSON tree describing the laser's properties.
 */
@Override
public JsonElement toJson() {
    Gson gson = new GsonBuilder().registerTypeAdapter(DefaultLaser.class, new DefaultStageSerializer())
            .create();
    return gson.toJsonTree(this);
}

From source file:ch.epfl.leb.sass.models.fluorophores.internal.DefaultFluorophore.java

License:Open Source License

/**
 * Returns the fluorophore's properties as a JSON string.
 * @return The properties of the fluorophore as a JSON string.
 *///w  w  w.j a v  a2  s  . co  m
@Override
public JsonElement toJson() {
    Gson gson = new GsonBuilder()
            .registerTypeAdapter(DefaultFluorophore.class, new DefaultFluorophoreSerializer()).create();
    return gson.toJsonTree(this);
}

From source file:ch.epfl.leb.sass.models.fluorophores.internal.PhysicalFluorophore.java

License:Open Source License

/**
 * Returns the fluorophore's properties as a JSON string.
 * @return The properties of the fluorophore as a JSON string.
 *//*from w  ww.  j a  v  a2s. c  om*/
@Override
public JsonElement toJson() {
    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PhysicalFluorophore.class, new PhysicalFluorophoreSerializer()).create();
    return gson.toJsonTree(this);
}

From source file:ch.epfl.leb.sass.simulator.internal.DefaultSimulator.java

License:Open Source License

/**
 * Saves the messages in the cache to a select file.
 * //from   w w w  .  ja  v a2 s.co  m
 * @param file The file to save to.
 */
public void saveMessages(File file) {
    JsonElement json = toJsonMessages();
    try (Writer writer = new FileWriter(file)) {
        Gson gson = new GsonBuilder().create();
        gson.toJson(json, writer);
    } catch (IOException ex) {
        String err = "Could not write simulation Messages to the file.";
        LOGGER.log(Level.WARNING, err);
        ex.printStackTrace();
    } catch (Exception ex) {
        String err = "An unknown error occurred while saving messages to " + "the file.";
        LOGGER.log(Level.WARNING, err);
        ex.printStackTrace();
    }
}

From source file:ch.epfl.leb.sass.simulator.internal.DefaultSimulator.java

License:Open Source License

/**
 * Saves the current state of the simulation.
 * //  w  w  w. j  ava2  s .  c  o  m
 * @param file The file to save to.
 */
public void saveState(File file) {
    JsonElement json = toJsonState();
    try (Writer writer = new FileWriter(file)) {
        Gson gson = new GsonBuilder().create();
        gson.toJson(json, writer);
    } catch (IOException ex) {
        String err = "Could not write simulation state to the file.";
        LOGGER.log(Level.WARNING, err);
        ex.printStackTrace();
    } catch (Exception ex) {
        String err = "An unknown error occurred while saving the " + "simulation state to the file.";
        LOGGER.log(Level.WARNING, err);
        ex.printStackTrace();
    }
}