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

org.chobit.apt.JsonStringSerializer Maven / Gradle / Ivy

There is a newer version: 0.0.4
Show newest version
package org.chobit.apt;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * json序列化工具类
 *
 * @author robin
 */
public final class JsonStringSerializer {


    private static final ObjectMapper mapper = new ObjectMapper();

    private static final Logger logger = LoggerFactory.getLogger(JsonStringSerializer.class);


    public static String toJson(Object obj) {
        try {
            return mapper.writeValueAsString(obj);
        } catch (JacksonException e) {
            logger.warn("json serialize error.", e);
            return String.valueOf(obj);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy