2017-07-24 42 views
1

我正在開發JPA-Hibernate項目。我有一個日期deserilaze問題,但我也在下面的解決方案。如何在java中繼承@JsonFormat註解?

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss.S") 
private Date createdAt; 

當我使用@JsonFormat註解與日期,我解決了問題,但我不想每個日期變量使用此註釋。我想要使​​用MyDate註釋,如下所示。

import java.lang.annotation.ElementType; 
import java.lang.annotation.Inherited; 
import java.lang.annotation.Retention; 
import java.lang.annotation.RetentionPolicy; 
import java.lang.annotation.Target; 

import com.fasterxml.jackson.annotation.JsonFormat; 

@Inherited 
@Target({ ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE }) 
@Retention(RetentionPolicy.RUNTIME) 
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss.S") 
public @interface MyDate { 

} 

當我使用@MyDate批註時,它無法正常工作。我一直在失敗,就像我從未使用過它。我的錯誤是什麼?

回答