com.inpaas.http.utils.JSON Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of inpaas-httpclient Show documentation
Show all versions of inpaas-httpclient Show documentation
HTTP Client for REST and SOAP Services
package com.inpaas.http.utils;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
public class JSON {
private static ObjectWriter writer;
private static final ObjectWriter getWriter() {
if (writer == null) writer = new ObjectMapper().writerWithDefaultPrettyPrinter();
return writer;
}
public static final String stringify(Object data) {
try {
return getWriter().writeValueAsString(data);
} catch (Exception e) {
StringWriter sw = new StringWriter();
sw.write(e.getMessage().concat("\n"));
e.printStackTrace(new PrintWriter(sw));
return sw.toString();
}
}
public static final void stringify(Object data, PrintStream out) {
out.println(JSON.stringify(data));
}
public static final I parse(String json, Class clazz) throws IOException {
return new ObjectMapper().readValue(json, clazz);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy