List of utility methods to do Json to Object
T | jsonToObj(String json, Class json To Obj if (json == null) return null; try { return objectMapper.readValue(json, clazz); } catch (Exception e) { throw new IllegalStateException("Unable to parse Json String.", e); |
T | jsonToObj(String json, Classconvert json string to class Object.try { return MAPPER.readValue(json, valueType); } catch (Exception ex) { throw new RuntimeException(ex); |
T | jsonToObject(String json, Class json To Object if (json == null) { return null; try { return objectMapper.readValue(json, toValueType); } catch (Exception e) { throw new RuntimeException("json to object failed :" + e.getMessage()); |
T | jsonToObject(String jsonString, Class json To Object Gson gson = new GsonBuilder().registerTypeHierarchyAdapter(Date.class, new JsonSerializer<Date>() { @Override public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { SimpleDateFormat format = new SimpleDateFormat(dateformat); return new JsonPrimitive(format.format(src)); }).setDateFormat(dateformat).create(); Object object = gson.fromJson(jsonString, (Type) classOfT); ... |
T | jsonToPojo(String jsonData, Class json To Pojo try { T t = MAPPER.readValue(jsonData, beanType); return t; } catch (Exception e) { e.printStackTrace(); return null; |
Map | parse(String jsonLine) parse Map jsonJavaRootObject = new Gson().fromJson(jsonLine, Map.class); return jsonJavaRootObject; |
T | readValue(String jsonStr, Class read Value ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); try { return objectMapper.readValue(jsonStr, valueType); } catch (Exception e) { e.printStackTrace(); return null; ... |
String | stringForJSON(String input) Format String for JSON Serialization if (input == null || input.isEmpty()) return ""; final int len = input.length(); final StringBuilder result = new StringBuilder(len + len / 4); final StringCharacterIterator iterator = new StringCharacterIterator(input); char ch = iterator.current(); while (ch != CharacterIterator.DONE) { if (ch == '\n') { ... |