Jackson提供了一个元注释(用于注释另一个注释的注释),称为
@JacksonAnnotationsInside,它是:
Meta-annotation (annotations used on other annotations) used for
indicating that instead of using target annotation (annotation
annotated with this annotation), Jackson should use meta-annotations
it has.
This can be useful in creating “combo-annotations” by having a
container annotation, which needs to be annotated with this annotation
as well as all annotations it ‘contains’.
所以,你应该创建一个像这样的注释:
@Target(value = { ElementType.TYPE, ElementType.METHOD,
ElementType.PARAMETER, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotationsInside //
@Transient
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = BaseEntity.JSON_DATETIME_FORMAT)
public @interface TransientLocalDateTime {
}
并且使用就像:
@TransientLocalDateTime
public LocalDateTime getCreatedDateDT() {
return DateTimeUtils.klabTimestampToLocalDateTime(getCreatedDate(), createdDateDT);
}