List of utility methods to do Json Create
JsonArray | emptyArray() Convenience to build an empty JsonArray
return Json.createArrayBuilder().build();
|
String | getJson(T t) get Json return G.toJson(t);
|
String | object2JsonDateSerializer(Object obj, final String dateformat) object Json Date Serializer String jsonStr = null; Gson gson = new GsonBuilder().registerTypeHierarchyAdapter(Date.class, new JsonSerializer<Date>() { public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { SimpleDateFormat format = new SimpleDateFormat(dateformat); return new JsonPrimitive(format.format(src)); }).setDateFormat(dateformat).create(); if (gson != null) { ... |
E | toBean(Class To bean e. ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setDateFormat(new SimpleDateFormat(DATE_FORMAT_DEF)); objectMapper.getDeserializationConfig().with(new SimpleDateFormat(DATE_FORMAT_DEF)); StringWriter stringWriter = new StringWriter(); return objectMapper.readValue(json, clazz); |
String | toJson(E e) To json string. ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setDateFormat(new SimpleDateFormat(DATE_FORMAT_DEF)); StringWriter stringWriter = new StringWriter(); objectMapper.writeValue(stringWriter, e); return stringWriter.toString(); |
String | toJSON(Map Convert a map to a JSON string. ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd")); try { return mapper.writeValueAsString(map); } catch (JsonProcessingException e) { throw new RuntimeException(e); |
String | toJson(Object object) to Json ObjectMapper mapper = new ObjectMapper(); mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); try { return mapper.writeValueAsString(object); } catch (JsonProcessingException e) { return ""; |
String | toJson(Object object, String dateFormat) to Json ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setDateFormat(new SimpleDateFormat(dateFormat)); objectMapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true); try { return objectMapper.writeValueAsString(object); } catch (Exception e) { e.printStackTrace(); return null; |
String | toJsonString(Map map) to Json String StringBuilder sb = new StringBuilder(); sb.append("{"); for (Object entryO : map.entrySet()) { if (sb.length() > 1) { sb.append(","); Entry entry = (Entry) entryO; sb.append("\""); ... |
List | toList(String json, Class to List return (List<T>) readValue(json, clz);
|