List of usage examples for com.google.gson GsonBuilder registerTypeAdapter
@SuppressWarnings({ "unchecked", "rawtypes" }) public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter)
From source file:com.ryanantkowiak.jOptionsHouseAPI.OhLogout.java
License:Open Source License
public static OhMsgAuthLogoutRsp build(String str) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ErrorMap.class, new ErrorMapDeserializer()); Gson gson = gsonBuilder.create();/* w ww . ja va2 s. co m*/ OhMsgAuthLogoutRsp rsp = (gson.fromJson(str, OhMsgAuthLogoutRsp.class)); rsp.m_raw = str; return rsp; }
From source file:com.ryanantkowiak.jOptionsHouseAPI.OhOrderDetails.java
License:Open Source License
public static OhMsgOrderDetailsRsp build(String str) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ErrorMap.class, new ErrorMapDeserializer()); Gson gson = gsonBuilder.create();/* w w w . j av a 2s . c o m*/ OhMsgOrderDetailsRsp rsp = (gson.fromJson(str, OhMsgOrderDetailsRsp.class)); rsp.m_raw = str; return rsp; }
From source file:com.ryanantkowiak.jOptionsHouseAPI.OhOrderHistory.java
License:Open Source License
public static OhMsgOrderHistoryRsp build(String str) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ErrorMap.class, new ErrorMapDeserializer()); Gson gson = gsonBuilder.create();/* w w w .j a v a 2 s.c o m*/ OhMsgOrderHistoryRsp rsp = (gson.fromJson(str, OhMsgOrderHistoryRsp.class)); rsp.m_raw = str; return rsp; }
From source file:com.ryanantkowiak.jOptionsHouseAPI.OhQuote.java
License:Open Source License
public static OhMsgViewQuoteListRsp build(String str) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ErrorMap.class, new ErrorMapDeserializer()); Gson gson = gsonBuilder.create();/* ww w. j a va2 s .co m*/ OhMsgViewQuoteListRsp rsp = gson.fromJson(str, OhMsgViewQuoteListRsp.class); rsp.m_raw = str; return rsp; }
From source file:com.ryanantkowiak.jOptionsHouseAPI.OhSimpleOrder.java
License:Open Source License
public static OhMsgCreateSimpleOrderRsp build(String str) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ErrorMap.class, new ErrorMapDeserializer()); Gson gson = gsonBuilder.create();//from w w w . j av a 2s .c om OhMsgCreateSimpleOrderRsp rsp = (gson.fromJson(str, OhMsgCreateSimpleOrderRsp.class)); rsp.m_raw = str; return rsp; }
From source file:com.ryanantkowiak.jOptionsHouseAPI.OhViewSeries.java
License:Open Source License
public static OhMsgViewSeriesRsp build(String str) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ErrorMap.class, new ErrorMapDeserializer()); Gson gson = gsonBuilder.create();/*from w ww .j ava2 s. c o m*/ OhMsgViewSeriesRsp rsp = (gson.fromJson(str, OhMsgViewSeriesRsp.class)); rsp.m_raw = str; return rsp; }
From source file:com.sangupta.jerry.util.GsonUtils.java
License:Apache License
/** * Register custom adapters for Gson/*w w w . java2 s .c o m*/ * * @param gsonBuilder */ private static void registerMoreTypeAdapters(GsonBuilder gsonBuilder) { if (customAdapters == null || customAdapters.isEmpty()) { return; } Set<Type> keySet = customAdapters.keySet(); for (Type key : keySet) { List<Object> values = customAdapters.getValues(key); if (values != null) { for (Object value : values) { gsonBuilder.registerTypeAdapter(key, value); } } } }
From source file:com.SatanicSpider.Serialization.Serilization.java
public Serilization() { //TODO: Make this dynamically find and instantiate GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Body.class, new BodySerializer()); //gsonBuilder.registerTypeAdapter(Entity.class, new EntitySerializer()); gson = gsonBuilder.create();/*from w ww. ja v a2 s . c o m*/ }
From source file:com.scvngr.levelup.core.model.factory.json.GsonModelFactory.java
License:Apache License
/** * Constructs a new factory./* ww w . ja va 2 s .c om*/ * * @param typeKey the key which the object to parse can be nested under. It will usually be the * name of the object's type: * * <pre> * { "typeKey": { "field1": "test" } } * </pre> * * When requesting a single object or a list of objects, the object will be nested under * this type key. * @param type the type of object to load * @param wrapped if true, the input JSON must be wrapped with a JSON object that has a typeKey, * as mentioned above. */ public GsonModelFactory(@NonNull final String typeKey, @NonNull final Class<T> type, final boolean wrapped) { mType = type; mTypeKey = typeKey; final GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); gsonBuilder.registerTypeAdapter(MonetaryValue.class, new MonetaryValueTypeAdapter()); gsonBuilder.registerTypeAdapter(Uri.class, new UriTypeAdapter()); gsonBuilder.registerTypeAdapterFactory(new RequiredFieldTypeAdapterFactory()); if (wrapped) { gsonBuilder.registerTypeAdapterFactory(new WrappedModelTypeAdapterFactory(type, typeKey)); } onBuildFactory(gsonBuilder); mGson = NullUtils.nonNullContract(gsonBuilder.create()); }
From source file:com.scvngr.levelup.core.model.factory.json.PermissionsRequestJsonFactory.java
License:Apache License
@Override protected void onBuildFactory(@NonNull final GsonBuilder gsonBuilder) { gsonBuilder.registerTypeAdapter(PermissionsRequest.State.class, new TypeAdapter<PermissionsRequest.State>() { @Override// w w w. jav a 2 s . c om public State read(final JsonReader reader) throws IOException { return State.forString(NullUtils.nonNullContract(reader.nextString())); } @Override public void write(final JsonWriter writer, final State value) throws IOException { writer.value(value.toString()); } }); }