将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