scala中使用fastjson把对象转换成json报错,提示:method toJSONString in class JSON of type (x$1: Any)String

提问者:帅平 问题分类:大数据
scala中使用fastjson把对象转换成json报错,提示:
ambiguous reference to overloaded definition,
both method toJSONString in class JSON of type (x: Any, x: com.alibaba.fastjson.serializer.SerializerFeature*)String
and  method toJSONString in class JSON of type (x: Any)String
match argument types (com.kafka.producer.UserPoJo)
    JSON.toJSONString(user)
2 个回答
安若兮
安若兮
这是因为scala语言中不能匹配java的多态,所以这里我们可以写成:
JSON.toJSONString(user,new SerializeConfig(true))

这样就不会报错了。
发布于:3个月前 (01-25) IP属地:未知
我来回答