一个项目需要大量使用杰克逊注解的以下组合。那么,有没有办法创建另一个注释以避免丑陋的复制/粘贴:
public class A {
@JsonProperty("_id")
@JsonSerialize(using=IdSerializer.class)
@JsonDeserialize(using=IdDeserializer.class)
String id;
}
public class B {
@JsonProperty("_id")
@JsonSerialize(using=IdSerializer.class)
@JsonDeserialize(using=IdDeserializer.class)
String id;
}
public class C {
@CustomId // don't repeat that configuration endlessly
String id;
}
更新:我试过这个,没有成功:-(
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotationsInside
@JsonProperty("_id")
@JsonSerialize(using=IdSerializer.class, include=JsonSerialize.Inclusion.NON_NULL)
@JsonDeserialize(using=IdDeserializer.class)
public @interface Id {}
public class D {
@Id
private String id;
}