jackson为什么不能将json转换成非静态嵌套类?

非静态嵌套类(non-static nested class),也被称为内部类(inner class),实际上是一个语法糖,在编译之后会变成和外部类同级别的类,只是会持有外部类的引用,而且会生成一个参数为外部类的有参构造函数,但jackson 在反序列化的时候需要一个无参构造函数,因此就会出问题。

解决方案

使用静态嵌套类

参考:
http://www.cowtowncoder.com/blog/archives/2010/08/entry_411.html
https://stackoverflow.com/questions/70324/java-inner-class-and-static-nested-class
http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html

posted @ 2022-05-09 19:00  被迫沉迷代码的CC  阅读(116)  评论(0)    收藏  举报