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

com.base4j.mvc.util.JsonUtils Maven / Gradle / Ivy

The newest version!
package com.base4j.mvc.util;

import java.io.IOException;

import com.base4j.mvc.conf.JacksonCustomObjectMapper;
import com.fasterxml.jackson.core.JsonProcessingException;

public class JsonUtils {
    private static JacksonCustomObjectMapper objectMapper = new JacksonCustomObjectMapper();
    
    public static String toJSONString(Object object) {
        try {
            return objectMapper.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            throw new IllegalArgumentException(e);
        }
    }
    public static  T parseObject(String json, Class clazz) {
        try {
            return objectMapper.readValue(json, clazz);
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
    }
    public static JacksonCustomObjectMapper getObjectMapper() {
        return objectMapper;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy