我已经定制了Jackson序列化器和反序列化器。反序列化器对于从REST服务返回的对象非常有效。例如:
class Data {
@JsonSerialize(using = SecureIdSerializer.class, as=String.class)
private String id;
}
@RequestMapping(GET)
Data getData() {
return someData;
}
它将转换此id字符串。但是对于String作为RequestParam传递给服务的情况,spring不会触发Jackson。例如:
@RequestMapping(GET)
void doSometing(
@JsonDeserialize(using = SecureIdDeserializer.class, as = String.class)
@RequestParam(value = "id", required = true) final String id) {
...
}
如何强制spring用我的反序列化器序列化String?