0.美图
1.问题
Error:(108, 47) 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 (org.apache.spark.sql.entity.LineageParseResult) and expected result type String
val response = new Request(url).body(JSON.toJSONString(lineageParseResult)).POST
2.原因
开始在java中,我使用方法
NodeDto nodeDto = getNodeInfo();
return new Request(masterPath + "/heartbeat",credentials)
.body(JSON.toJSONString(nodeDto))
.POST();
去执行一个远程调用,后来我在scala中也这样执行,就报错了
val url = "http://localhost:8003/dubhe/api/v1/node/checkPrivilegesJsonString"
val jsonString = JSON.toJSONString(lineageParseResult)
val response = new Request(url).body(jsonString).POST
出于某种原因,Scala重载逻辑与Java逻辑不匹配。你必须像这样称呼它:
JSON.toJSONString(map, SerializerFeature.PrettyFormat)
最后代码改成
val url = "http://localhost:8003/dubhe/api/v1/node/checkPrivilegesJsonString"
val jsonString = JSON.toJSONString(lineageParseResult, SerializerFeature.PrettyFormat)
val response = new Request(url).body(jsonString).POST
就好了