首先,我有:
public class Person {
private String name;
@JsonSerialize(using=SSNJsonSerializer.class)
private SSN ssn;
}
这有效..
现在我有一个“包装类”,例如:
public class Response {
private Integer total;
@JsonSerializer(contentUsing=ResponseJsonSerializer.class)
private List<Object> itens;
private Boolean success;
}
itens 可以是人员列表。但我不能序列化(人的)所有字段。ResponseJsonSerializer 知道可以写什么;
Insite ResponseJsonSerializer,我有:
jgen.writeObjectField(name, field.get(value) );
但控制台说:No serializer found for class ...SSN and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) )
我如何在 ResponseJsonSerializer 中使用在字段上声明的序列化程序?