我一直在升级到一个新版本的杰克逊(即从org.codehaus.致com.fasterxml.)突然间,我面临着许多奇怪的错误。经过几个小时的努力和调整,我仍然无法让它工作,所以我问你们是否可以帮助我。
我有以下方法:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("getTerminalsByIdAndLocation")
List<SearchResultDto> getTerminalsByIdAndLocation(@QueryParam("location") String location, @QueryParam("id") Integer id) throws BusinessException;而函数实现只是在存储库中进行查找。
SearchResultDto看起来如下所示:
@JsonIgnoreProperties(ignoreUnknown = true)
public class SearchResultDto implements Serializable {
private static final long serialVersionUID = 1L;
private TerminalId terminalId;
private Integer location;
private String streetNumber;
private String postalcoldeCity;
private Status status;
// getters and setters with no annotation or so
}当我现在调用我的方法时,我得到以下错误:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: object is not an instance of declaring class (through reference chain: java.util.ArrayList[0]-><long package>.SearchResultDto["terminalId"])
经过多次尝试后,我认为我只需删除terminalId,然后它将更改为:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: object is not an instance of declaring class (through reference chain: java.util.ArrayList[0]-><long package>AtmSearchResultDto["location"])
我是无知的,这里有什么问题吗?
编辑
除了String streetNumber之外,我还尝试在所有东西上使用@JsonIgnore,但同样的例外只发生在streetNumber上。
发布于 2017-02-14 19:28:05
长话短说:我搞砸了类路径,有两个类加载器,REST方法的实现称为数据库模块的存储库,它从不同的类加载器那里获得实例。在调整我的maven作用域和导入类型之后,它现在开始工作了!
发布于 2018-05-09 13:55:46
我有一个类似的问题,问题是我的POJO之一是final。删除最后一个关键字就成功了。
public final class AccessControlMap extends HashMap<Permission, Set<AccessType>>
//Before
public final class AccessType {
//After
public class AccessType {https://stackoverflow.com/questions/42232802
复制相似问题