1

In our code we currently use the Jackson @JsonFormat annotation on a date object as follows:

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssZZ")
private Date startDate;

Is there a class which defines constants for these patterns in order to avoid having such hardcoded value? Something like:

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DateTimePatterns.ISO_DATETIME_TIMEZONE)
private Date startDate;

Or should I just create my own constants-class?

eol
  • 23,236
  • 5
  • 46
  • 64
  • 1
    If it is possible you should use `Java 8` `Time` package. See: [Spring Boot Jackson date and timestamp Format](https://stackoverflow.com/questions/55256567/spring-boot-jackson-date-and-timestamp-format/55270120#55270120), [Converting between java.time.LocalDateTime and java.util.Date](https://stackoverflow.com/questions/19431234/converting-between-java-time-localdatetime-and-java-util-date). If you do not use this pattern in many places there is no point to extract it somewhere. If you use, create your own class with constant. – Michał Ziober Oct 24 '19 at 15:32

0 Answers0