io.github.robothy.sdwebui.sdk.utils.JsonUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdwebui-java-sdk Show documentation
Show all versions of sdwebui-java-sdk Show documentation
Stable Diffusion Web UI Java SDK
The newest version!
package io.github.robothy.sdwebui.sdk.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
public class JsonUtils {
private static final ObjectMapper objectMapper = new ObjectMapper();
public static String toJson(Object object) {
try {
return objectMapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
public static T fromJson(String json, Class clazz) {
try {
return objectMapper.readValue(json, clazz);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
public static T fromJson(InputStream inputStream, Class clazz) {
try {
return objectMapper.readValue(inputStream, clazz);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}