-
Notifications
You must be signed in to change notification settings - Fork 200
JSON Date Formatting
Ryan Heaton edited this page Mar 4, 2016
·
1 revision
By default, Enunciate assumes that dates and other timestamps are to be serialized in JSON as numbers. This aligns with the default behavior of the Jackson JSON processor that Enunciate assumes is being used.
Jackson offers a number of ways to specify that dates should be serialized as strings instead of numbers. For more information, see Jackson FAQ: Date Handling.
Enunciate honors the @JsonFormat
annotation, e.g.:
public class DateStuff {
@JsonFormat( shape=JsonFormat.Shape.STRING )
public Date creationTime;
}
Enunciate also honors the Enunciate-specific @TypeHint
annotation, e.g.:
public class DateStuff {
@TypeHint( String.class )
public Date creationTime;
}
As of Enunciate 2.3, each JSON module can be configured to change the default date format, e.g.:
<enunciate>
<modules>
<!--Jackson 2 module configuration: -->
<jackson dateFormat="string"/>
<!--Jackson 1 module configuration: -->
<jackson1 dateFormat="string"/>
</modules>
</enunciate>