Note that there are some explanatory texts on larger screens.

plurals
  1. PORESTEasy and ContextResolver<ObjectMapper> for Jackson
    primarykey
    data
    text
    <p>I have a problem with the customization of my RESTEasy JSON response.</p> <p>In <code>web.xml</code> I use autoscan:</p> <pre><code>&lt;context-param&gt; &lt;param-name&gt;resteasy.scan&lt;/param-name&gt; &lt;param-value&gt;true&lt;/param-value&gt; &lt;/context-param&gt; </code></pre> <p>Here is my customization class for <code>ObjectMapper</code>, (I've set not null fields and new human readable date):</p> <pre><code>@Provider @Produces(MediaType.APPLICATION_JSON) public class JacksonConfig implements ContextResolver&lt;ObjectMapper&gt; { private Logger log = Logger.getLogger(PropertiesConfig.LOG_CATEGORY); private ObjectMapper objectMapper; public JacksonConfig() throws Exception { objectMapper = new ObjectMapper(); objectMapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); objectMapper.setDateFormat(new SimpleDateFormat("dd.MM.yyyy")); objectMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); } @Override public ObjectMapper getContext(Class&lt;?&gt; arg0) { return objectMapper; } } </code></pre> <p>Here is my servlet:</p> <pre><code>@Path("/search") public class Search extends ArtesAPI { @GET @Path("/") @Produces(MediaType.APPLICATION_JSON) public Response search(@Context HttpServletRequest request){ RequestManager reqManager = new RequestManager(request); MyResponse response = reqManager.doSearchRequest(); return Response.status(200).entity(response).build(); } } </code></pre> <p>When I deploy to the server, RESTEasy prints this log:</p> <pre><code>10:43:44,320 INFO [TomcatDeployment] deploy, ctxPath=/MyServer 10:43:44,544 INFO [ConfigurationBootstrap] Adding scanned @Provider: myserver.servlets.JacksonConfig 10:43:44,545 INFO [ConfigurationBootstrap] Adding scanned resource: myserver.servlets.Search </code></pre> <p>But when I call the search API, I receive this response: (here a little part of response)</p> <pre><code>{ "entry": [ { "name": "abbigliamento", "description": null, "lastUpdate": 1375448941000, "subCategory": null }, { "name": "car", "description": null, "lastUpdate": null, "subCategory": null } } </code></pre> <p>My server response gives me null fields and <code>lastUpdate</code> in milliseconds.</p> <p>Where have I gone wrong?</p> <p>Thanks in advance.</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.
 

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