Note that there are some explanatory texts on larger screens.

plurals
  1. POJackson JSON not serializing Joda DateTime correctly
    primarykey
    data
    text
    <p>I have a Joda DateTime in an Order class:</p> <pre><code>public class Order { private DateTime creationTime; ... } </code></pre> <p>I have initialized my mapper as follows:</p> <pre><code>mapper.configure( SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); </code></pre> <p>When I serialize this class, I expect to see creationTime serialized in the ISO-8601 format as follows</p> <pre><code>{ "creationTime" : "2011-01-01T09:00:00.000-04:00" } </code></pre> <p>This is working perfectly fine in my unit test. However, in my web application, the exact same code is serializing all the DateTime fields:</p> <pre><code>{ "creationTime" : { "year" : 2011, "dayOfMonth" : 17, "dayOfWeek" : 7, "era" : 1, "dayOfYear" : 107, "weekOfWeekyear" : 15, "weekyear" : 2011, "monthOfYear" : 4, "yearOfEra" : 2011, "yearOfCentury" : 11, "centuryOfEra" : 20, "millisOfSecond" : 590, "millisOfDay" : 40311590, "secondOfMinute" : 51, "secondOfDay" : 40311, "minuteOfHour" : 11, "minuteOfDay" : 671, "hourOfDay" : 11, "millis" : 1303053111590, "zone" : { "fixed" : false, "uncachedZone" : { "cachable" : true, "fixed" : false, "id" : "America/New_York" }, "id" : "America/New_York" }, "chronology" : { "zone" : { "fixed" : false, "uncachedZone" : { "cachable" : true, "fixed" : false, "id" : "America/New_York" }, "id" : "America/New_York" } } } </code></pre> <p>What am I missing? I am including jackson-core-asl-1.7.6.jar and jackson-mapper-asl-1.7.6.jar in my classpath in both cases.</p> <p>In some online examples I saw an annotation on DateTime. I don't know if this is needed, but I tried it nevertheness. See below:</p> <pre><code>public class Order { @JsonSerialize(using=DateTimeSerializer.class) private DateTime creationTime; ... } </code></pre> <p>This seems to make no difference.</p> <p>Thanks.</p> <p>P.S. Does anyone know if the Jackson mailing list is working? I posted this question on the user mailing list, but it doesn't show in the archives. The last post in the archives is dated 24 June 2010.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload