g0c00l.g33k
g0c00l.g33k

Reputation: 2608

Java annotation to transform a json field

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

How 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

Answers (1)

john16384
john16384

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

Related Questions