【发布时间】:2016-01-26 08:08:51
【问题描述】:
我已经编写了我的 CustomJsonSerializer,我希望它能够自动序列化所有使用 @JsonProperty 注释的字段,所以我只留下序列化那些没有注释且需要“特别注意”的字段。
例如:我有Pojo
类播放器{
@JsonProperty(user_id)
private long userId;
private byte[] history;
}
我的自定义序列化器:
public class JsonPlayerSerializer extends JsonSerializer<Player> {
@Override
public void serialize(Player player, JsonGenerator gen,
SerializerProvider provider) throws IOException, JsonProcessingException {
// I would like to add some code here that automatically would add all annotated fields.
gen.writeObjectField("history_moves", new JsonObject().put("$binary", myMoves));
}
}
【问题讨论】: