将java类转成json对象

public static  <T, t> String classToJson(Class clazz) throws IllegalAccessException, InstantiationException {
        SerializerFeature[] serializer = {SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullNumberAsZero,
                SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteNullBooleanAsFalse};

        Class<t> c= clazz;
        T t= (T) c.newInstance();
        String s = JSONObject.toJSONString(t, serializer);
        return s;
    }

借助fastjson

原文地址:https://www.cnblogs.com/zhizhu1120418975/p/13091858.html