0

My rest service is calling another Rest API using sprint rest template. Java class corresponding to Request body has one field is of type Date (java.util.date) as application source is 1.6 java. Now the corresponding request class of the receiver Rest API has the same field of type java.time.Instant.

Now when I call this rest endpoint, date is received at their side as completely different. I was searching for any annotation jackson provides, thinking that it will de-serialize this value in correct way. But I could not see any solution anywhere. Can anyone suggests what is the best way to fix this

akr
  • 123
  • 1
  • 1
  • 9

1 Answers1

0

There is no such annotation. You can write your custom deserializer where you take the content of the field and parse it to Instant, or you modify your receiving class to have Date field and class Date has a method toInstant() (See here). So using this method you can easily convert your Date to Instant on the Java side and not on JSON side.

Michael Gantman
  • 7,315
  • 2
  • 19
  • 36