Java Utililty Methods Json Format

List of utility methods to do Json Format

Description

The list of methods to do Json Format are organized into topic(s).

Method

StringformatJson(Object object)
format Json
ObjectMapper om = new ObjectMapper();
om.enable(SerializationFeature.INDENT_OUTPUT);
om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
return om.writeValueAsString(object);
StringformatJson(String content)
format Json
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(content).getAsJsonObject();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
return json == null ? "" : gson.toJson(json);
StringformatJSON(String jsonData)
format JSON
Object obj = mapper.readValue(jsonData, Object.class);
return toJSON(obj);