org.springframework.social.partnercenter.serialization.Json Maven / Gradle / Ivy
package org.springframework.social.partnercenter.serialization;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
public class Json {
private static ObjectMapper objectMapper;
static {
objectMapper = new ObjectMapper();
}
public static T fromJson(String jsonString, Class targetClass){
try {
ObjectReader reader = objectMapper.reader(targetClass);
return reader.readValue(jsonString);
} catch (IOException e) {
throw new JsonSerializationException(e);
}
}
public static String toJson(T objectToSerialize){
try {
return objectMapper.writer().writeValueAsString(objectToSerialize);
} catch (JsonProcessingException e) {
throw new JsonSerializationException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy