Reputation: 2608
I am trying to come up with an interface that has pretty non-standard way of representing fields as it is fed from a legacy system, this interface seems to require some custom validations + transformations such as
YYYMMDD
and transforming it to a date field of yyyy-MM-dd
format in the setterHow do I come up with custom annotations that can do this using @interface
? I was able to find @Constraint(validatedBy=someclass.class)
but there doesn't seem to be something to transform the data (or sorry if I haven't looked enough).. Any pointers on this would be helpful.
Upvotes: 0
Views: 705
Reputation: 8044
In Java, you just use the "transformed" DataType in your Jackson annotated objects, for example:
private TransformedData data;
Then you configure Jackson with a deserializer that accepts a String and returns a "TransformedData" object. When Jackson is trying to fill in your data field, it will notice that it needs conversion and call your deserializer.
Upvotes: 0