All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hcxprotocol.utils.JSONUtils Maven / Gradle / Ivy

Go to download

The SDK for HCX Participant System to help in integrating with HCX Gateway easily.

There is a newer version: 1.0.8
Show newest version
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);
    }

}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy