List of usage examples for com.google.gson GsonBuilder create
public Gson create()
From source file:com.ikanow.infinit.e.data_model.index.BaseIndexPojo.java
License:Apache License
@SuppressWarnings("unchecked") public static <S extends BaseIndexPojo> S fromIndex(String s, TypeToken<S> type, BasePojoIndexMap<S> dynamicMap) { GsonBuilder gb = null; try {/*from w w w. ja v a 2 s .com*/ Class<S> clazz = (Class<S>) type.getType(); gb = ((S) clazz.newInstance()).extendBuilder(BaseIndexPojo.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.index.BaseIndexPojo.java
License:Apache License
public static <S extends BaseIndexPojo> String listToIndex(Collection<S> list, TypeToken<? extends Collection<S>> listType, BasePojoIndexMap<S> dynamicMap) { GsonBuilder gb = null; try {/*from w ww . j a v a2 s .c o m*/ if (!list.isEmpty()) { gb = list.iterator().next().extendBuilder(BaseIndexPojo.getDefaultBuilder()); } } catch (Exception e) { return null; } return gb.create().toJson(list, listType.getType()); }
From source file:com.ikanow.infinit.e.data_model.index.BaseIndexPojo.java
License:Apache License
@SuppressWarnings("unchecked") public static <S extends BaseIndexPojo, L extends Collection<S>> L listFromIndex(String bson, TypeToken<? extends L> listType, BasePojoIndexMap<S> dynamicMap) { GsonBuilder gb = null; try {//from w w w . java 2s .c om Class<S> clazz = (Class<S>) ((ParameterizedType) listType.getType()).getActualTypeArguments()[0]; // (know this works because of construction of listType) gb = (clazz.newInstance()).extendBuilder(BaseIndexPojo.getDefaultBuilder()); } catch (Exception e) { return null; } if (null != dynamicMap) { gb = dynamicMap.extendBuilder(gb); } return (L) gb.create().fromJson(bson, listType.getType()); }
From source file:com.ikanow.infinit.e.data_model.index.IndexManager.java
License:Apache License
public static <S> JsonElement mapToIndex(S s, BasePojoIndexMap<S> docMap) { GsonBuilder gb = BaseIndexPojo.getDefaultBuilder(); if (null != docMap) { gb = docMap.extendBuilder(gb);/*from www. jav a 2 s .c o m*/ } return gb.create().toJsonTree(s); }
From source file:com.ikanow.infinit.e.data_model.index.IndexManager.java
License:Apache License
public static <S> S mapFromIndex(String s, Class<S> type, BasePojoIndexMap<S> docMap) { GsonBuilder gb = BaseIndexPojo.getDefaultBuilder(); if (null != docMap) { gb = docMap.extendBuilder(gb);//from w w w . j av a 2 s . c om } return gb.create().fromJson(s, type); }
From source file:com.ikanow.infinit.e.data_model.index.IndexManager.java
License:Apache License
@SuppressWarnings("unchecked") public static <S> S mapFromIndex(String s, TypeToken<S> type, BasePojoIndexMap<S> docMap) { GsonBuilder gb = BaseIndexPojo.getDefaultBuilder(); if (null != docMap) { gb = docMap.extendBuilder(gb);/*www . j av a 2s . c o m*/ } return (S) gb.create().fromJson(s, type.getType()); }
From source file:com.ikanow.infinit.e.data_model.index.IndexManager.java
License:Apache License
public static <S> JsonElement mapListToIndex(Collection<S> list, TypeToken<? extends Collection<S>> listType, BasePojoIndexMap<S> docMap) { GsonBuilder gb = BaseIndexPojo.getDefaultBuilder(); if (null != docMap) { gb = docMap.extendBuilder(gb);// w w w .j av a2 s . co m } return gb.create().toJsonTree(list, listType.getType()); }
From source file:com.ikanow.infinit.e.data_model.index.IndexManager.java
License:Apache License
@SuppressWarnings("unchecked") public static <S, L extends Collection<S>> L mapListFromIndex(String json, TypeToken<? extends L> listType, BasePojoIndexMap<S> docMap) { GsonBuilder gb = BaseIndexPojo.getDefaultBuilder(); if (null != docMap) { gb = docMap.extendBuilder(gb);/*from ww w .j a v a2 s. co m*/ } return (L) gb.create().fromJson(json, listType.getType()); }
From source file:com.ikanow.infinit.e.data_model.store.BaseDbPojo.java
License:Apache License
public static <S extends BaseDbPojo> DBObject toDb(S s, BasePojoDbMap<S> dynamicMap) { GsonBuilder gb = s.extendBuilder(BaseDbPojo.getDefaultBuilder()); if (null != dynamicMap) { gb = dynamicMap.extendBuilder(gb); }/*w w w. java 2s . com*/ return (DBObject) MongoDbUtil.encode(gb.create().toJsonTree(s).getAsJsonObject()); }
From source file:com.ikanow.infinit.e.data_model.store.BaseDbPojo.java
License:Apache License
public static <S extends BaseDbPojo> S fromDb(DBObject s, Class<S> type, BasePojoDbMap<S> dynamicMap) { if (null == s) return null; // Create a new instance of the class in order to override it GsonBuilder gb = null; try {/*from w ww . j a v a 2 s . c o m*/ gb = type.newInstance().extendBuilder(BaseDbPojo.getDefaultBuilder()); } catch (Exception e) { return null; } if (null != dynamicMap) { gb = dynamicMap.extendBuilder(gb); } return gb.create().fromJson(MongoDbUtil.encode(s), type); }