jackson2报错
package com.pft.pves.utils; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; public class NetUtil { public static void main(String[] args) { String str="{"Operation":"login","data":{"account":"sjdnbd","disabled":false,"imei":"354113060211698","password":"shdnd"}}"; ObjectMapper mapper = new ObjectMapper(); RequestBody<User> rb = mapper.convertValue(str, new TypeReference<RequestBody<User>>() {}); System.out.println(rb.getOperation()); }}
错误信息Exception in thread "main" java.lang.IllegalArgumentException: Can not instantiate value of type [simple type, class com.pft.pves.utils.RequestBody<com.pft.pves.utils.User>] from String value; no single-String constructor/factory method at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:2704) at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:2646) at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:2637) at com.pft.pves.utils.NetUtil.main(NetUtil.java:14) Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class com.pft.pves.utils.RequestBody<com.pft.pves.utils.User>] from String value; no single-String constructor/factory method at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator._createFromStringFallbacks(StdValueInstantiator.java:428) at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:299) at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1150) at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:139) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:126) at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:2699) ... 3 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不懂了,请问convertValue是干哈的··
Can not instantiate value of type [simple type,class com.pft.pves.utils.RequestBody<com.pft.pves.utils.User>] from String value; no single-String constructor/factory method
这个类没有合适的构造方法,