http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+ <!--
+ I am declaring my beans without the automatic annotation. :/
+ Better because we are saving memory but it requires more configuration.
+
+ See: org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser
+ <mvc:annotation-driven/>
+ -->
+
+
<context:annotation-config />
<context:component-scan base-package="de.spring.webservices.rest"/>
</bean>
</property>
<property name="messageConverters" ref="messageConverters" />
+
+
+ <property name="requestBodyAdvice">
+ <util:list>
+ <bean id="requestBodyAdvice" class="org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice"/>
+ </util:list>
+ </property>
+
+
<property name="responseBodyAdvice">
<util:list>
<bean id="responseBodyAdvice" class="org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice"/>
@Test
public void testWhenGetAllCarsThenRetrieveJsonValues() throws Exception {
mockMvc.perform(get("/api/cars/")
- .accept(MediaType.APPLICATION_JSON_UTF8_VALUE))
+ .accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].id", any(Integer.class)))
.andExpect(jsonPath("$[1].id", any(Integer.class)))
.andExpect(jsonPath("$[2].content", is("Car: 3")))
.andExpect(jsonPath("$[2].id", any(Integer.class)))
- .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
}
@Test
public void testWhenGetOneCarThenRetrieveJsonValue() throws Exception {
mockMvc.perform(get("/api/cars/{id}", 1L)
- .accept(MediaType.APPLICATION_JSON_UTF8_VALUE))
+ .accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk())
.andExpect(jsonPath("id", any(Integer.class)))
.andExpect(jsonPath("content", is("Car: 1")))
- .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
}
@Test
public void testWhenCreateNewCarThenRetrieveJsonValue() throws Exception {
Car car = new Car(2L, "nothing");
mockMvc.perform(post("/api/cars/")
- .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
+ .contentType(MediaType.APPLICATION_JSON_UTF8)
.content(asJsonString(car))
- .accept(MediaType.APPLICATION_JSON_UTF8_VALUE))
+ .accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isCreated())
.andExpect(jsonPath("id", any(Integer.class)))
.andExpect(jsonPath("content", is("Car: 1")))
.andExpect(header().string(HttpHeaders.LOCATION, "/api/cars/1"))
- .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
}
private static String asJsonString(final Object obj) throws JsonProcessingException {