scala 调用fastjson 的toJSONString() 报错
可变参数需要慎用,不然scala 调用的时候会出现以下问题。
Error:(29, 31) ambiguous reference to overloaded definition, both method toJSONString in object JSON of type (x$1: Any, x$2: com.alibaba.fastjson.serializer.SerializerFeature*)String and method toJSONString in object JSON of type (x$1: Any)String match argument types (com.sydney.dream.example.fastjson.module.Group) val jsonString = JSON.toJSONString(group)
public static String toJSONString(Object object) { return toJSONString(object, new SerializerFeature[0]); } public static String toJSONString(Object object, SerializerFeature... features) { SerializeWriter out = new SerializeWriter(); try { JSONSerializer serializer = new JSONSerializer(out); for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) { serializer.config(feature, true); } serializer.write(object); return out.toString(); } finally { out.close(); } }
所以我们调用的时候,显式调用不定长参数的方法。 JSON.toJSONString(group, new Array)