io.hcxprotocol.utils.JSONUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hcx-integrator-sdk Show documentation
Show all versions of hcx-integrator-sdk Show documentation
The SDK for HCX Participant System to help in integrating with HCX Gateway easily.
package io.hcxprotocol.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.experimental.UtilityClass;
import java.util.Base64;
/**
* The JSON Utils to convert a Java object to JSON string and vise versa.
*/
@UtilityClass
public class JSONUtils {
private static final ObjectMapper mapper = new ObjectMapper();
public static T decodeBase64String(String encodedString, Class clazz) throws JsonProcessingException {
byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
String decodedString = new String(decodedBytes);
return deserialize(decodedString, clazz);
}
public static String serialize(Object obj) throws JsonProcessingException {
return mapper.writeValueAsString(obj);
}
public static T deserialize(String value, Class clazz) throws JsonProcessingException {
return mapper.readValue(value, clazz);
}
}