List of usage examples for com.google.gson GsonBuilder GsonBuilder
public GsonBuilder()
From source file:com.ankang.report.util.GsonUtil.java
License:Mozilla Public License
public static <T> T fromJson(String json, Class<T> clasz) { Gson gson = new GsonBuilder().create(); return gson.fromJson(json, clasz); }
From source file:com.ankang.report.util.GsonUtil.java
License:Mozilla Public License
public static <T> T fromJson(String json, Type typeOfT) { Gson gson = new GsonBuilder().create(); return gson.fromJson(json, typeOfT); }
From source file:com.ankang.report.util.GsonUtil.java
License:Mozilla Public License
public static String toJson(Object src) { Gson gson = new GsonBuilder().create(); return gson.toJson(src); }
From source file:com.ankang.report.util.GsonUtil.java
License:Mozilla Public License
public static String toJsonSerializeNulls(Object src) { Gson gson = new GsonBuilder().serializeNulls().create(); return gson.toJson(src); }
From source file:com.ankang.report.util.GsonUtil.java
License:Mozilla Public License
public static String get(String key, String snapshot) { if (StringUtils.isBlank(key) || StringUtils.isBlank(snapshot)) { return null; }//from ww w . j a va 2 s .c o m Gson gson = new GsonBuilder().create(); Map<String, String> map = null; try { map = gson.fromJson(snapshot, new TypeToken<Map<String, Object>>() { }.getType()); } catch (Exception ex) { ex.printStackTrace(); } if (MapUtils.isEmpty(map)) { return null; } return map.get(key); }
From source file:com.ankang.report.util.GsonUtil.java
License:Mozilla Public License
public static String put(String snapshot, String key, String value) { Gson gson = new GsonBuilder().create(); Map<String, String> map = gson.fromJson(snapshot, new TypeToken<Map<String, Object>>() { }.getType());//from ww w . jav a 2 s .com map.put(key, value); return gson.toJson(map); }
From source file:com.ankang.report.util.GsonUtil.java
License:Mozilla Public License
public static Map<String, Object> jsonToMapEx(String jsonStr) { Gson gson = new GsonBuilder().registerTypeAdapter(new TypeToken<Map<String, Object>>() { }.getType(), new IntegerFirstSOMapDeserializer()).create(); java.lang.reflect.Type type = new com.google.gson.reflect.TypeToken<Map<String, Object>>() { }.getType();// w w w. j ava 2s. c o m Map<String, Object> objMap = gson.fromJson(jsonStr, type); return objMap; }
From source file:com.antew.redditinpictures.library.image.FlickrImageType.java
License:Apache License
/** * Resolve an image from Flickr// www.j av a2 s. c om * * @param hash * The hash to resolve * * @return A {@link Flickr} instance */ public static Flickr resolveFlickrImageFromHash(String hash) { Flickr flickr = null; if (hash != null) { Gson gson = new GsonBuilder().registerTypeAdapter(Boolean.class, new BooleanDeserializer()).create(); try { String json = SynchronousNetworkApi.downloadUrl(String.format(FLICKR_URL, hash)); flickr = gson.fromJson(json, Flickr.class); } catch (JsonSyntaxException e) { Ln.e(e, "Error parsing JSON in resolveFlickrImage"); } } return flickr; }
From source file:com.antew.redditinpictures.library.json.JsonDeserializer.java
License:Apache License
public static Gson getGson() { if (gson == null) { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(Vote.class, new VoteAdapter()); builder.serializeNulls();//w ww. ja v a 2 s. c om gson = builder.create(); } return gson; }