在使用JSON.toJSONString
将对象转化为json字符串是,使用如下操作:
import com.alibaba.fastjson.JSON
val accompany_rank = rankQueryRemoteService.queryRankList(request)
JSON.toJSONString(accompany_rank)
结果运行是报错了
Error:(26, 10) ambiguous reference to overloaded definition,
both method toJSONString in class JSON of type (x$1: Any, x$2: com.alibaba.fastjson.serializer.SerializerFeature*)String
and method toJSONString in class JSON of type (x$1: Any)String
match argument types (com.yupaopao.platform.common.dto.Response[com.yupaopao.platform.common.dto.PageResult[com.yupaopao.platform.rank.api.response.TopsRankDTO]]) and expected result type String
JSON.toJSONString(accompany_rank)
出于某种原因,Scala重载逻辑与Java逻辑不匹配。需要使用:
JSON.toJSONString(map, SerializerFeature.PrettyFormat)
将原有代码修改为
import com.alibaba.fastjson.JSON
val accompany_rank = rankQueryRemoteService.queryRankList(request)
JSON.toJSONString(accompany_rank, SerializerFeature.PrettyFormat)
就可以了