We am writing Integration testcases for Rest API, where in we are validating the type of all the properties of Response DTO. In the DTO we have one property of type java.util.Date.
However, when it try to use
Expected: is an instance of java.util.Date
but: <2343240000L> is a java.lang.Long
Spring uses Jackson to serialize JSON and Jackson serialize dates as milliseconds by default as @Reddy says. Try annotate the testDate field in your DTO with
@Temporal annotation if you want the date in this format: YYYY-MM-DD
If you want it in another format try with
@DateTimeFormat(pattern = "dd/MM/yyyy")
and change the pattern with the one you want.
If these two solutions do not work you have to define a custom serializer for date fields to solve the problem and annotate the get method of your date fields with the
JsonDateSerializer would be your custom serializer class.
For more detail about the custom serializer see this answer http://stackoverflow.com/a/38186623/6503002