List of usage examples for com.google.gson GsonBuilder create
public Gson create()
From source file:com.ikanow.infinit.e.data_model.api.BaseApiPojo.java
License:Apache License
public static <S extends BaseApiPojo> String toApi(S s, BasePojoApiMap<S> dynamicMap) { GsonBuilder gb = s.extendBuilder(BaseApiPojo.getDefaultBuilder()); if (null != dynamicMap) { gb = dynamicMap.extendBuilder(gb); }/*from w ww . j av a2s .c o m*/ return gb.create().toJson(s); }
From source file:com.ikanow.infinit.e.data_model.api.BaseApiPojo.java
License:Apache License
public static <S extends BaseApiPojo> S fromApi(String s, Class<S> type, BasePojoApiMap<S> dynamicMap) { // Create a new instance of the class in order to override it GsonBuilder gb = null; try {// w w w . ja v a 2s . com gb = type.newInstance().extendBuilder(BaseApiPojo.getDefaultBuilder()); } catch (Exception e) { return null; } if (null != dynamicMap) { gb = dynamicMap.extendBuilder(gb); } return gb.create().fromJson(s.toString(), type); }
From source file:com.ikanow.infinit.e.data_model.api.BaseApiPojo.java
License:Apache License
public static <S extends BaseApiPojo> S fromApi(JsonElement j, Class<S> type, BasePojoApiMap<S> dynamicMap) { // Create a new instance of the class in order to override it GsonBuilder gb = null; try {// w w w.j a v a 2 s . c o m gb = type.newInstance().extendBuilder(BaseApiPojo.getDefaultBuilder()); } catch (Exception e) { return null; } if (null != dynamicMap) { gb = dynamicMap.extendBuilder(gb); } return gb.create().fromJson(j, type); }
From source file:com.ikanow.infinit.e.data_model.api.BaseApiPojo.java
License:Apache License
@SuppressWarnings("unchecked") public static <S extends BaseApiPojo> S fromApi(String s, TypeToken<S> type, BasePojoApiMap<S> dynamicMap) { GsonBuilder gb = null; try {/*from w w w. j av a2 s. c om*/ Class<S> clazz = (Class<S>) type.getType(); gb = ((S) clazz.newInstance()).extendBuilder(BaseApiPojo.getDefaultBuilder()); } catch (Exception e) { return null; } if (null != dynamicMap) { gb = dynamicMap.extendBuilder(gb); } return (S) gb.create().fromJson(s.toString(), type.getType()); }
From source file:com.ikanow.infinit.e.data_model.api.BaseApiPojo.java
License:Apache License
@SuppressWarnings("unchecked") public static <S extends BaseApiPojo> S fromApi(JsonElement j, TypeToken<S> type, BasePojoApiMap<S> dynamicMap) { GsonBuilder gb = null; try {/*from w ww . ja v a 2s . c om*/ Class<S> clazz = (Class<S>) type.getType(); gb = ((S) clazz.newInstance()).extendBuilder(BaseApiPojo.getDefaultBuilder()); } catch (Exception e) { return null; } if (null != dynamicMap) { gb = dynamicMap.extendBuilder(gb); } return (S) gb.create().fromJson(j, type.getType()); }
From source file:com.ikanow.infinit.e.data_model.api.BaseApiPojo.java
License:Apache License
public static <S extends BaseApiPojo> String listToApi(Collection<S> list, TypeToken<? extends Collection<S>> listType, BasePojoApiMap<S> dynamicMap) { GsonBuilder gb = null; try {//from w w w .j av a2 s.c om if (!list.isEmpty()) { gb = list.iterator().next().extendBuilder(BaseApiPojo.getDefaultBuilder()); } } catch (Exception e) { return null; } return gb.create().toJson(list, listType.getType()); }
From source file:com.ikanow.infinit.e.data_model.api.BaseApiPojo.java
License:Apache License
@SuppressWarnings("unchecked") public static <S extends BaseApiPojo, L extends Collection<S>> L listFromApi(String json, TypeToken<? extends L> listType, BasePojoApiMap<S> dynamicMap) { GsonBuilder gb = null; try {/*from ww w . j a v a 2 s .c o m*/ Class<S> clazz = (Class<S>) ((ParameterizedType) listType.getType()).getActualTypeArguments()[0]; // (know this works because of construction of listType) gb = (clazz.newInstance()).extendBuilder(BaseApiPojo.getDefaultBuilder()); } catch (Exception e) { return null; } if (null != dynamicMap) { gb = dynamicMap.extendBuilder(gb); } return (L) gb.create().fromJson(json, listType.getType()); }
From source file:com.ikanow.infinit.e.data_model.api.BaseApiPojo.java
License:Apache License
@SuppressWarnings("unchecked") public static <S extends BaseApiPojo, L extends Collection<S>> L listFromApi(JsonElement json, TypeToken<? extends L> listType, BasePojoApiMap<S> dynamicMap) { GsonBuilder gb = null; try {/*from w w w . j a va2s . co m*/ Class<S> clazz = (Class<S>) ((ParameterizedType) listType.getType()).getActualTypeArguments()[0]; // (know this works because of construction of listType) gb = (clazz.newInstance()).extendBuilder(BaseApiPojo.getDefaultBuilder()); } catch (Exception e) { return null; } if (null != dynamicMap) { gb = dynamicMap.extendBuilder(gb); } return (L) gb.create().fromJson(json, listType.getType()); }
From source file:com.ikanow.infinit.e.data_model.index.BaseIndexPojo.java
License:Apache License
public static <S extends BaseIndexPojo> String toIndex(S s, BasePojoIndexMap<S> dynamicMap) { GsonBuilder gb = s.extendBuilder(BaseIndexPojo.getDefaultBuilder()); if (null != dynamicMap) { gb = dynamicMap.extendBuilder(gb); }// w w w . j a v a 2 s . com return gb.create().toJson(s); }
From source file:com.ikanow.infinit.e.data_model.index.BaseIndexPojo.java
License:Apache License
public static <S extends BaseIndexPojo> S fromIndex(String s, Class<S> type, BasePojoIndexMap<S> dynamicMap) { // Create a new instance of the class in order to override it GsonBuilder gb = null; try {/* w w w. ja v a 2 s. c om*/ gb = type.newInstance().extendBuilder(BaseIndexPojo.getDefaultBuilder()); } catch (Exception e) { return null; } if (null != dynamicMap) { gb = dynamicMap.extendBuilder(gb); } return gb.create().fromJson(s.toString(), type); }