'What should be @JsonFormat(pattern="") in Spring-boot for given example
Using Spring-boot RESTful service,in that receiving JSON file which contain DateTime in following format "2017-08-16T16:08:25.000Z" and JsonFormat tries are e.g
@JsonFormat(pattern="yyyy-MM-dd HH:mm")
@JsonFormat(JsonFormat.Shape.STRING,pattern="yyyy-MM-dd@HH:mm:ss.SSSZ")
but none of format match accepting. jar used as shown below:
import com.fasterxml.jackson.annotation.JsonFormat;
so what should be JSON format pattern to accept such json data -Date with Time
Solution 1:[1]
You need to read the javadocs carefully.
Quoting from the javadoc of @JsonFormat
Date
: Shape can beJsonFormat.Shape.STRING
orJsonFormat.Shape.NUMBER
; pattern may containSimpleDateFormat
-compatible pattern definition.
and quoting from the javadoc of SimpleDateFormat
:
Within date and time pattern strings, unquoted letters from
'A'
to'Z'
and from'a'
to'z'
are interpreted as pattern letters [...].
Text can be quoted using single quotes ('
) to avoid interpretation.
Hence you need to use 'T'
instead of T
in the pattern for @JsonFormat
:
pattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |