首先,我有:
public class Person {
private String name;
@JsonSerialize(using=SSNJsonSerializer.class)
private SSN ssn;
}
这有效..
现在我有一个'wrapper classe',如:
public class Response {
private Integer total;
@JsonSerializer(contentUsing=ResponseJsonSerializer.class)
private List<Object> itens;
private Boolean success;
}
itens可以是人员列表。但是我无法序列化所有字段(Person)。 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中使用在字段上声明的序列化程序?