JAX-RS Jackson Json Vendor Format Release Date

WRT to the next question:

Serializing a Jersey + Jackson JSON Date Format - How to change the format or use a custom JacksonJsonProvider .

I want to know

  • Is Jackson an indication that the json date format should be normalized to a unix integer?

Follow-up questions ...

  • Has there been a change in his position recently?
  • Shouldn't the date format be normalized in the same format as provided by jaxb xml output?
  • why / why not?
  • any efforts to solve this problem?
  • Did RestEasy provide a json provider mitigation that would issue a json date in a public date format?
+6
source share
2 answers

Sorry people were screaming out loud - I found the answers here.

http://wiki.fasterxml.com/JacksonFAQDateHandling ,

here

http://wiki.fasterxml.com/JacksonFAQ#Serializing_Dates ,

here

http://wiki.fasterxml.com/JacksonHowToCustomSerializers

here

http://jackson.codehaus.org/1.1.2/javadoc/org/codehaus/jackson/map/util/StdDateFormat.html

Using the @JsonSerialize method (using = ...):

public class JsonStdDateSerializer extends JsonSerializer<Date> { private static final DateFormat iso8601Format = StdDateFormat.getBlueprintISO8601Format(); @Override public void serialize( Date date, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { // clone because DateFormat is not thread-safe DateFormat myformat = (DateFormat) iso8601Format.clone(); String formattedDate = myformat.format(date); jgen.writeString(formattedDate); } } 
+11
source

This is also controlled by the ObjectMapper function (at least in version 1.9.11 and, possibly, earlier):

 ObjectMapper om = new ObjectMapper(); om.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); om.writer().writeValue(System.out, objectWithDateProperty); 

I do not see how to declaratively execute the equivalent of the definition of the object itself.

+2
source

Source: https://habr.com/ru/post/919156/


All Articles