List of usage examples for com.google.gson GsonBuilder create
public Gson create()
From source file:com.ibm.watson.developer_cloud.util.GsonSingleton.java
License:Open Source License
/** * Creates a {@link com.google.gson.Gson} object that can be use to serialize and deserialize Java objects. * * @param prettyPrint if true the JSON will be pretty printed * @return the {@link Gson}//from w ww. j ava 2s . c o m */ private static Gson createGson(Boolean prettyPrint) { GsonBuilder builder = new GsonBuilder(); registerTypeAdapters(builder); if (prettyPrint) { builder.setPrettyPrinting(); } builder.disableHtmlEscaping(); return builder.create(); }
From source file:com.ikanow.infinit.e.api.knowledge.QueryHandler.java
License:Open Source License
public static AdvancedQueryPojo createQueryPojo(String queryJson) { GsonBuilder gb = AdvancedQueryPojo.getDefaultBuilder(); gb.registerTypeAdapter(AdvancedQueryPojo.QueryRawPojo.class, new AdvancedQueryPojo.QueryRawPojo.Deserializer()); AdvancedQueryPojo query = gb.create().fromJson(queryJson, AdvancedQueryPojo.class); // Fill in the blanks (a decent attempt has been made to fill out the blanks inside these options) if (null == query.input) { query.input = new AdvancedQueryPojo.QueryInputPojo(); }//from ww w.ja v a 2s.c o m if (null == query.score) { query.score = new AdvancedQueryPojo.QueryScorePojo(); } if (null == query.output) { query.output = new AdvancedQueryPojo.QueryOutputPojo(); } if (null == query.output.docs) { // (Docs are sufficiently important we'll make sure they're always present) query.output.docs = new AdvancedQueryPojo.QueryOutputPojo.DocumentOutputPojo(); } return query; }
From source file:com.ikanow.infinit.e.data_model.api.ApiManager.java
License:Apache License
public static <S> String mapToApi(S s, BasePojoApiMap<S> apiMap) { GsonBuilder gb = BaseApiPojo.getDefaultBuilder(); if (null != apiMap) { gb = apiMap.extendBuilder(gb);//from w ww . j av a 2 s . c o m } return gb.create().toJson(s); }
From source file:com.ikanow.infinit.e.data_model.api.ApiManager.java
License:Apache License
public static <S> S mapFromApi(String s, Class<S> type, BasePojoApiMap<S> apiMap) { GsonBuilder gb = BaseApiPojo.getDefaultBuilder(); if (null != apiMap) { gb = apiMap.extendBuilder(gb);/*from w ww.j a va2s. co m*/ } return gb.create().fromJson(s, type); }
From source file:com.ikanow.infinit.e.data_model.api.ApiManager.java
License:Apache License
public static <S> S mapFromApi(JsonElement j, Class<S> type, BasePojoApiMap<S> apiMap) { GsonBuilder gb = BaseApiPojo.getDefaultBuilder(); if (null != apiMap) { gb = apiMap.extendBuilder(gb);/*from w ww . ja v a2 s . c o m*/ } return gb.create().fromJson(j, type); }
From source file:com.ikanow.infinit.e.data_model.api.ApiManager.java
License:Apache License
@SuppressWarnings("unchecked") public static <S> S mapFromApi(String s, TypeToken<S> type, BasePojoApiMap<S> apiMap) { GsonBuilder gb = BaseApiPojo.getDefaultBuilder(); if (null != apiMap) { gb = apiMap.extendBuilder(gb);/*from w w w . j a v a 2 s. co m*/ } return (S) gb.create().fromJson(s, type.getType()); }
From source file:com.ikanow.infinit.e.data_model.api.ApiManager.java
License:Apache License
@SuppressWarnings("unchecked") public static <S> S mapFromApi(JsonElement j, TypeToken<S> type, BasePojoApiMap<S> apiMap) { GsonBuilder gb = BaseApiPojo.getDefaultBuilder(); if (null != apiMap) { gb = apiMap.extendBuilder(gb);/*from w ww .j a v a 2 s .c o m*/ } return (S) gb.create().fromJson(j, type.getType()); }
From source file:com.ikanow.infinit.e.data_model.api.ApiManager.java
License:Apache License
public static <S> String mapListToApi(Collection<S> list, TypeToken<? extends Collection<S>> listType, BasePojoApiMap<S> apiMap) { GsonBuilder gb = BaseApiPojo.getDefaultBuilder(); if (null != apiMap) { gb = apiMap.extendBuilder(gb);/*from w ww. j a v a2 s . com*/ } return gb.create().toJson(list, listType.getType()); }
From source file:com.ikanow.infinit.e.data_model.api.ApiManager.java
License:Apache License
@SuppressWarnings("unchecked") public static <S, L extends Collection<S>> L mapListFromApi(String json, TypeToken<? extends L> listType, BasePojoApiMap<S> apiMap) { GsonBuilder gb = BaseApiPojo.getDefaultBuilder(); if (null != apiMap) { gb = apiMap.extendBuilder(gb);//ww w .ja v a2 s .c o m } return (L) gb.create().fromJson(json, listType.getType()); }
From source file:com.ikanow.infinit.e.data_model.api.ApiManager.java
License:Apache License
@SuppressWarnings("unchecked") public static <S, L extends Collection<S>> L mapListFromApi(JsonElement json, TypeToken<? extends L> listType, BasePojoApiMap<S> apiMap) { GsonBuilder gb = BaseApiPojo.getDefaultBuilder(); if (null != apiMap) { gb = apiMap.extendBuilder(gb);/*from w ww . ja v a 2s .c o m*/ } return (L) gb.create().fromJson(json, listType.getType()); }