有这样一个Task数据类:

1
2
3
4
5
6
7
8
9
10
11
data class Task(  
    val id: Int = -1,
    val userId: Int,
    val start: LatLonPoint,
    val end: LatLonPoint,
    val completed: LatLonPoint,
    val schedule: Float,
    val isAward: Int,
    val integral: Int,
    val tripMode: String
)

由于kotlin会为这个类生产getter、setter方法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public final class Task {
private final int id;
private final int userId;
private final float schedule;
private final int isAward;
private final int integral;
@NotNull
private final String tripMode;

public final int getId() {
return this.id;
}

public final int getUserId() {
return this.userId;
}

public final float getSchedule() {
return this.schedule;
}

public final int isAward() {
return this.isAward;
}

public final int getIntegral() {
return this.integral;
}

@NotNull
public final String getTripMode() {
return this.tripMode;
}
}

可以看到大部分字段都会生成对应的get方法,但是isAward字段,生成的方法不是get开头的,而jackson序列化时,查找的是类的get方法,导致了序列化时,丢失了isAward字段。