Scala当使用fast json将对象转为json字符串:
JSON.toJSONString(对象实例)
报错如下:
Error:(218, 34) 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.aura.gmall.realtime.bean.OrderDetailWide) and expected result type String
JSON.toJSONString(orderDetailWide))
原因:
JSON.toJSONString(对象实例)是java api的用法,Scala如果要使用fast json转字符串,需要加参数new SerializeConfig(true)。
解决方法:
JSON.toJSONString(对象实例,new SerializeConfig(true)))