【发布时间】:2018-11-12 12:09:59
【问题描述】:
我正在尝试让 Jackson 反序列化
{
"test": 2018
}
到
SomeJavaClass:
private final Test test
但我想使用 Project Lombok 制作我的测试类。然而,Lombok 使用 ConstructorProperties 注释该类,并且由于某种原因这使得杰克逊失败。
我的课程如下所示:
@Value
public class SomeJavaClass {
Test test;
}
@Value
public class Test{
String value;
}
测试被分解为:
public class Test {
int value;
@java.beans.ConstructorProperties({"value"})
public Test(final int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
public boolean equals(final Object o) {
if (o == this) {
return true;
}
if (!(o instanceof Test)) {
return false;
}
final Test other = (Test) o;
if (this.getValue() != other.getValue()) {
return false;
}
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + this.getValue();
return result;
}
public String toString() {
return "Test(value=" + this.getValue() + ")";
}
}
是否有可能让杰克逊以某种方式忽略构造函数属性?
【问题讨论】:
-
@JsonIgnoreProperties(ignoreUnknown = true) 对你有用吗?或类似问题的答案stackoverflow.com/questions/12835911/…
-
请添加完整的源代码,包括所有 Lombok 注释。
-
GitHub上有一个关于这个问题的问题:github.com/meltmedia/jackson-crypto/issues/6
-
那么错误是什么,是如何让Jackson失败的呢?你使用什么注释?
@AllArgsConstructor?