class JacksonError(
val x: String,
val isSomething: Boolean
)
因错误而失败
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "something" (class ch.cypherk.blah.JacksonError), not marked as ignorable (2 known properties: "x", "isSomething"])
而没有这样的问题
class NoJacksonError(
val x: String,
val something: Boolean
)
我的第一直觉是 Jackson 不理解isXY-getters 而它只需要getters 开始get。
然而,有趣的是,也没有问题
class AlsoNoJacksonError (
val x: String,
var isSomething: Boolean
)
这意味着我不知道发生了什么。
JacksonError被编译为
public final class ch.cypherk.blah.JacksonError {
public final java.lang.String getX();
Code:
0: aload_0
1: getfield #11 // Field x:Ljava/lang/String;
4: areturn
public final boolean isSomething();
Code:
0: aload_0
1: getfield #18 // Field isSomething:Z
4: ireturn
public ch.cypherk.blah.JacksonError(java.lang.String, boolean);
Code:
0: aload_1
1: ldc #21 // String x
3: invokestatic #27 // Method kotlin/jvm/internal/Intrinsics.checkParameterIsNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
6: aload_0
7: invokespecial #30 // Method java/lang/Object."<init>":()V
10: aload_0
11: aload_1
12: putfield #11 // Field x:Ljava/lang/String;
15: aload_0
16: iload_2
17: putfield #18 // Field isSomething:Z
20: return
}
NoJacksonError被编译为
public final class ch.cypherk.blah.NoJacksonError {
public final java.lang.String getX();
Code:
0: aload_0
1: getfield #11 // Field x:Ljava/lang/String;
4: areturn
public final boolean getSomething();
Code:
0: aload_0
1: getfield #19 // Field something:Z
4: ireturn
}
RISEBY
相关分类