MockMvc ignores JsonFormat jackson annotation
<p>I set-up a REST API with Spring MVC and Spring HATEOAS. 
In one of the DTOs I put a JsonFormat on a ZonedDateTime field.</p>

<p>Running the server gives me the expected date format (yyyyMMdd), but with testing the annotation is ignored and I get something like 1454281200.000000000. So it looks like when testing the annotation is ignored totally. I tried the @JsonIgnore annotation, but that on was working.</p>

<p>No matter I use MockMvcBuilders.webAppContextSetup(wac).build() or MockMvcBuilders.standaloneSetup(membersController).build() the time is simply not converted to the JsonFormat as expected.</p>

<p>Anyone any idea's what going wrong here? I expect some configuration issue, but I don't know where to look at.</p>

<p>Discovered that the aDate on the Resource is serialised properly, but the xxxDTO.aDate is not serialised properly.</p>

<p>Resource</p>

<pre><code>public class XxxResource extends Resource&lt;XxxDTO&gt; {

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyyMMdd")
    private ZonedDateTime aDate;

    public XxxResource(XxxDTO xxxDTO) {
        super(xxxDTO);
        this.aDate = xxxDTO.getADate();
    }
}
</code></pre>

<p>DTO</p>

<pre><code>public class XxxDTO {
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyyMMdd")
    private ZonedDateTime aDate;
}
</code></pre>

<p>pom.xml</p>

<pre><code>    &lt;jackson.version&gt;2.8.3&lt;/jackson.version&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework&lt;/groupId&gt;
        &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
        &lt;version&gt;4.3.3-RELEASE&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
        &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;com.fasterxml.jackson.datatype&lt;/groupId&gt;
        &lt;artifactId&gt;jackson-datatype-jsr310&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
        &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.hateoas&lt;/groupId&gt;
        &lt;artifactId&gt;spring-hateoas&lt;/artifactId&gt;
        &lt;version&gt;0.20.0.RELEASE&lt;/version&gt;
    &lt;/dependency&gt;
</code></pre>

<p>Test setup</p>

<pre><code>@RunWith(MockitoJUnitRunner.class)
public class SomeTest {
   XxxController xxxController = new XxxController(XxxService, new XxxResourceAssembler(),
            new PagedResourcesAssembler&lt;&gt;(new HateoasPageableHandlerMethodArgumentResolver(), null));
   this.mockMvc = MockMvcBuilders.standaloneSetup(xxxController).setCustomArgumentResolvers
            (new PageableHandlerMethodArgumentResolver()).build();
}
</code></pre>

<p>The endpoints are set up through a web.xml and the WebMvcConfig is like this:</p>

<pre><code>@Configuration
@EnableWebMvc
@EnableSpringDataWebSupport
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addArgumentResolvers(List&lt;HandlerMethodArgumentResolver&gt; argumentResolvers) {
   argumentResolvers.add(new PageableHandlerMethodArgumentResolver());
    }

    @Bean
    public PagedResourcesAssembler pagedResourcesAssembler() {
    return new PagedResourcesAssembler(new HateoasPageableHandlerMethodArgumentResolver(), null);
    }
}
</code></pre>