cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to create custom annotation?

Huskar
Participant
0 Likes
972

I am using @Jsonformat to specify a date format for my attribute. But there is one problem that @Jsonformat usage SimpleDateFormat which accepts date as 32 jan. But it will calculate and assume date to be 1 Feb. I don't want this to happen. So I was planning to create a new annotation which will handle it and will not auto adjust anything. I can create a new annotaion and use it in my bean class but how can I write handler/serializer whatever we write to specify how operation will be performed?

Accepted Solutions (0)

Answers (3)

Answers (3)

arvind-kumar_avinash
Active Contributor
0 Likes

Hi - you need to define your custom annotation and then write a custom BeanPostProcessor so that Spring can recognize it e.g. https://www.baeldung.com/spring-annotation-bean-pre-processor

arvind-kumar_avinash
Active Contributor
0 Likes

Hi - did any of the solutions given in this page fulfil your requirement? If you implemented some other solution, please share that.

Huskar
Participant
0 Likes

Yes I have checked all the mentioned url's and thank you for that. But in all exaple you are using getAnnotation in main method. This is not how its done in spring right? Say @requestParam will simply pick value corrosponding to that attribute but we dont write that logic in controller. Its completely hidden. That is what I want.

Former Member
0 Likes