org.tangerine.apiresolver.util.JsonUtil Maven / Gradle / Ivy
package org.tangerine.apiresolver.util;
import java.io.Reader;
import java.lang.reflect.Type;
import com.google.gson.GsonBuilder;
public class JsonUtil {
private static GsonBuilder gsonBuilder = new GsonBuilder();
public static String toHtmlPrettyJson(Object object) {
String json = new GsonBuilder().setPrettyPrinting().create().toJson(object);
json = json.replace("\n", "
");
json = json.replace(" ", " ");
return json;
}
public static String toPrettyJson(Object object) {
GsonBuilder _gsonBuilder = new GsonBuilder();
_gsonBuilder.serializeNulls();
_gsonBuilder.setPrettyPrinting();
return _gsonBuilder.create().toJson(object);
}
public static T fromJson(String json, Class classOfT) {
return gsonBuilder.create().fromJson(json, classOfT);
}
public static T fromJson(Reader reader, Type typeOfT) throws Exception {
return gsonBuilder.create().fromJson(reader, typeOfT);
}
public static String toJson(Object src) {
return gsonBuilder.create().toJson(src);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy