java 组合注解_java – 将多个任意注释合并为一个

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);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值