title: Validate LocalDate in JSON response with Spring MockMVC
body: <p>I'm trying to validate a LocalDate object in a JSON result returned by a Spring MVC webservice but I can't figure out how.    </p>
  
  <p>At the moment I always run into assertion errors like the following one:</p>
  
  <blockquote>
    <p>java.lang.AssertionError: JSON path "$[0].startDate" Expected: is
    &lt;2017-01-01>
         but: was &lt;[2017,1,1]></p>
  </blockquote>
  
  <p>The important part of my test is posted below. Any ideas how to fix the test to pass?</p>
  
  <pre><code>import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup;
  
  public class WebserviceTest {
  
      @Mock
      private Service service;
  
      @InjectMocks
      private Webservice webservice;
  
      private MockMvc mockMvc;
  
      @Before
      public void before() {
          mockMvc = standaloneSetup(webservice).build();
      }
  
      @Test
      public void testLocalDate() throws Exception {
          // prepare service mock to return a valid result (left out)
  
          mockMvc.perform(get("/data/2017")).andExpect(status().isOk())
              .andExpect(jsonPath("$[0].startDate", is(LocalDate.of(2017, 1, 1))));
      }
  }
  </code></pre>
  
  <p>The webservice returns a list of view objects looking like this:</p>
  
  <pre><code>public class ViewObject {
  
      @JsonProperty
      private LocalDate startDate;
  }
  </code></pre>
  
  <p><em>[edit]</em></p>
  
  <p>Another try was </p>
  
  <pre><code>.andExpect(jsonPath("$[0].startDate", is(new int[] { 2017, 1, 1 })))
  </code></pre>
  
  <p>which resulted in</p>
  
  <blockquote>
    <p>java.lang.AssertionError: JSON path "$[0].startDate" Expected: is
    [&lt;2017>, &lt;1>, &lt;1>]
         but: was &lt;[2017,1,1]></p>
  </blockquote>
  
  <p><em>[edit 2]</em>
  The returned startDate object seems to be of type: <code>net.minidev.json.JSONArray</code></p>