Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was struggling with exactly the same b@#$d created by jackson from entity field with joda DayTime:</p> <pre><code>modifiedOn": { "year": 2013, "dayOfWeek": 6, "era": 1, "dayOfYear": 124, "dayOfMonth": 4, "weekOfWeekyear": 18, "monthOfYear": 5, "yearOfCentury": 13, "centuryOfEra": 20, "millisOfSecond": 0, "millisOfDay": 81801000, "secondOfMinute": 21, "secondOfDay": 81801, "minuteOfHour": 43, "minuteOfDay": 1363, "weekyear": 2013, "yearOfEra": 2013, "hourOfDay": 22, "millis": 1367700201000, "zone": { "uncachedZone": { "cachable": true, "fixed": false, "id": "Europe/Belgrade" }, "fixed": false, "id": "Europe/Belgrade" }, "chronology": { "zone": { "uncachedZone": { "cachable": true, "fixed": false, "id": "Europe/Belgrade" }, "fixed": false, "id": "Europe/Belgrade" } }, "afterNow": false, "beforeNow": true, "equalNow": false } </code></pre> <p>As is mentioned here <a href="https://github.com/FasterXML/jackson-datatype-joda" rel="nofollow">https://github.com/FasterXML/jackson-datatype-joda</a> it is very easy with Jackson 2.0 but for newbie like me it was quite hard to figure out how to make it works, but finally found working piece of code:</p> <p>Dependency in maven - that was simple</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;com.fasterxml.jackson.datatype&lt;/groupId&gt; &lt;artifactId&gt;jackson-datatype-joda&lt;/artifactId&gt; &lt;version&gt;2.1.2&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>and some code from FasterXML documentation </p> <pre><code>objectMapper mapper = new ObjectMapper(); mapper.registerModule(new JodaModule()); </code></pre> <p>... but how to implement it? Here is the example - new class:</p> <pre><code>public class JodaObjectMapper extends ObjectMapper { public JodaObjectMapper() { super(); registerModule(new JodaModule()); } } </code></pre> <p>And the last step - addition to spring.xml </p> <pre><code>&lt;mvc:annotation-driven&gt; &lt;mvc:message-converters register-defaults="true"&gt; &lt;bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"&gt; &lt;property name="objectMapper"&gt; &lt;bean class="net.jvw.JodaObjectMapper"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/mvc:message-converters&gt; &lt;/mvc:annotation-driven&gt; </code></pre> <p>So now let look on produced json</p> <pre><code>"modifiedOn": 1367701129075 </code></pre> <p>finally something easy to deal with </p> <p>From blog post <a href="http://vanwilgenburg.wordpress.com/2013/01/14/return-usable-joda-dates-in-json-with-jackson/" rel="nofollow">http://vanwilgenburg.wordpress.com/2013/01/14/return-usable-joda-dates-in-json-with-jackson/</a></p> <p>If somebody want to see more code of my entity class or controller - please ask in comment and I will add sufficient code to this answer.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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