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

com.rumwei.util.ObjectUtilGW Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
package com.rumwei.util;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;

import java.io.StringWriter;

/*
* @Author: guwei
* @Description: Object常用处理逻辑
* @Date: 2019-03-23
* */
@Slf4j
public class ObjectUtilGW {

    private static final ObjectMapper objectMapper = new ObjectMapper();

    static {
        objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES,true);  //parser是否允许单引号来包住属性名称和字符串值。
    }

    /*
    * @author guwei
    * @param Object
    * @return String
    * @exception
    * @Description convert a object to String
    * @Date 2019-03-23
    */
    public static String ObjectToJsonString(Object o) throws Exception{
        Preconditions.checkNotNull(o);
        return objectMapper.writeValueAsString(o);
    }



}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy