Example usage for com.google.gson GsonBuilder create

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

Introduction

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

Prototype

public Gson create() 

Source Link

Document

Creates a Gson instance based on the current configuration.

Usage

From source file:app.config.AppBootstrap.java

License:Apache License

public void init(AppContext context) {
    setInjector(Guice.createInjector(new GreeterModule()));
    Configuration.setUseDefaultLayoutForErrors(true);
    GsonBuilder jsonBuilder = new GsonBuilder();
    jsonBuilder.registerTypeAdapter(BaseCard.class, new BaseCardAdapter());
    context.set("json", jsonBuilder.create());
}

From source file:apprenda.clientservices.tasks.ApprendaDeployTask.java

License:Apache License

@NotNull
private Gson getGsonBuilder() {
    GsonBuilder builder = new GsonBuilder();
    return builder.create();
}

From source file:ar.com.wolox.wolmo.networking.di.modules.GsonModule.java

License:Open Source License

@Provides
static Gson provideGson(GsonBuilder gsonBuilder) {
    return gsonBuilder.create();
}

From source file:at.ac.tuwien.big.we14.lab2.api.impl.JSONQuestionDataProvider.java

License:Open Source License

@Override
public List<Category> loadCategoryData() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(Category.class, new CategoryDeserializer(factory));

    gsonBuilder.registerTypeAdapter(Question.class, new QuestionDeserialzier(factory));

    Gson gson = gsonBuilder.create();

    Type collectionType = new TypeToken<List<Category>>() {
    }.getType();//from   w  ww.  jav a2 s .  c  o  m
    List<Category> categories = gson.fromJson(new InputStreamReader(inputStream, Charsets.UTF_8),
            collectionType);

    return categories;
}

From source file:at.ac.tuwien.big.we15.lab2.api.impl.JSONQuestionDataProvider.java

License:Open Source License

@Override
public List<Category> getCategoryData() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(Category.class, new CategoryDeserializer());
    gsonBuilder.registerTypeAdapter(Question.class, new QuestionDeserialzier());

    Gson gson = gsonBuilder.create();
    Type collectionType = new TypeToken<List<Category>>() {
    }.getType();//from  w ww  . j  ava  2s  .c o m
    List<Category> categories = gson.fromJson(new InputStreamReader(inputStream, Charsets.UTF_8),
            collectionType);

    return categories;
}

From source file:at.alladin.rmbt.controlServer.ServerResource.java

License:Apache License

public static Gson getGson(boolean prettyPrint) {
    GsonBuilder gb = new GsonBuilder().registerTypeAdapter(DateTime.class, new MyDateTimeAdapter());
    if (prettyPrint)
        gb = gb.setPrettyPrinting();//from   www.  ja v a  2  s. c  om
    return gb.create();
}

From source file:at.illecker.storm.commons.util.io.JsonUtils.java

License:Apache License

public static List<Map<String, Object>> readJsonStream(InputStream jsonInputStream) {
    BufferedReader br = null;/*w w  w .  j  av  a  2s .  c om*/
    try {
        br = new BufferedReader(new InputStreamReader(jsonInputStream));
        GsonBuilder builder = new GsonBuilder();
        List<Map<String, Object>> elements = (List<Map<String, Object>>) builder.create().fromJson(br,
                Object.class);
        LOG.info("Loaded " + " elements: " + elements.size());
        return elements;
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException ignore) {
            }
        }
    }
}

From source file:at.medevit.elexis.emediplan.core.internal.EMediplanServiceImpl.java

License:Open Source License

@Override
public Medication createModelFromChunk(String chunk) {
    String json = getDecodedJsonString(chunk);
    if (chunk.length() > 8) {
        logger.debug("json version: " + chunk.substring(5, 8));
        GsonBuilder gb = new GsonBuilder();
        gb.registerTypeAdapter(Medication.class, new MedicationDeserializer());
        Gson g = gb.create();
        Medication m = g.fromJson(json, Medication.class);
        m.chunk = chunk;/*from   w w w. ja v  a  2s  .co m*/
        return m;
    } else {
        logger.error("invalid json length - cannot parseable");
    }

    return null;
}

From source file:au.com.iglooit.shar.model.vo.ClientFile.java

License:Apache License

/**
 * Construct a new ClientFile from its JSON representation.
 *
 * @param in Reader of JSON string to parse.
 *///from w w w . j  a va  2 s.  com
public ClientFile(Reader in) {
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();
    ClientFile other = gson.fromJson(in, ClientFile.class);
    if (StringUtils.isNotBlank(other.resourceId)) {
        this.resourceId = other.resourceId;
    }
    this.title = other.title;
    this.description = other.description;
    this.mimeType = other.mimeType;
    this.content = other.content;
    this.labels = other.labels;
    this.editable = other.editable;

}

From source file:au.com.iglooit.shar.model.vo.State.java

License:Apache License

/**
 * Create a new State given its JSON representation.
 *
 * @param json Serialized representation of a State.
 *///w  ww  . j  a v  a  2  s .  c o m
public State(String json) {
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();
    State other = gson.fromJson(json, State.class);
    this.action = other.action;
    this.ids = other.ids;
    this.folderId = other.folderId;
}