List of usage examples for com.google.gson.reflect TypeToken getType
public final Type 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);//from ww w . j av a 2s . c om } 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.j av a2 s. co m*/ } 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> S fromApi(String s, TypeToken<S> type, BasePojoApiMap<S> dynamicMap) { GsonBuilder gb = null;// w w w .j av a 2 s .c o m try { 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;/*from w w w.ja va 2 s . c om*/ try { 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;/*from w w w . jav a 2 s .c o m*/ try { 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;/* w w w.jav a 2 s . c o m*/ try { 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;// ww w . j av a 2s. c om try { 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
@SuppressWarnings("unchecked") public static <S extends BaseIndexPojo> S fromIndex(String s, TypeToken<S> type, BasePojoIndexMap<S> dynamicMap) { GsonBuilder gb = null;//from w ww . j av a 2 s.c o m try { 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;//from w w w .j ava2s.c o m try { 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;/*from ww w .jav a 2s. c o m*/ try { 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()); }