Refactor @JsonView support w/ ResponseBodyInterceptor

The newly added support for ResponseBodyInterceptor is a good fit for
the (also recently added) support for the Jackson @JsonView annotation.

This change refactors the original implementation of @JsonView support
for @ResponseBody and ResponseEntity controller methods this time
implemented as an ResponseBodyInterceptor.

Issue: SPR-7156
This commit is contained in:
Rossen Stoyanchev
2014-05-18 19:20:58 -04:00
parent 96b18c8dc2
commit 51fc3b4aaf
17 changed files with 321 additions and 134 deletions

View File

@@ -245,7 +245,7 @@ public class MappingJackson2HttpMessageConverterTests {
bean.setWithView1("with");
bean.setWithView2("with");
bean.setWithoutView("without");
MappingJacksonValueHolder jsv = new MappingJacksonValueHolder(bean, MyJacksonView1.class);
MappingJacksonValue jsv = new MappingJacksonValue(bean, MyJacksonView1.class);
this.converter.writeInternal(jsv, outputMessage);
String result = outputMessage.getBodyAsString(Charset.forName("UTF-8"));

View File

@@ -36,7 +36,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.json.MappingJacksonValueHolder;
import org.springframework.http.converter.json.MappingJacksonValue;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@@ -220,8 +220,8 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
HttpHeaders entityHeaders = new HttpHeaders();
entityHeaders.setContentType(new MediaType("application", "json", Charset.forName("UTF-8")));
MySampleBean bean = new MySampleBean("with", "with", "without");
MappingJacksonValueHolder jsv = new MappingJacksonValueHolder(bean, MyJacksonView1.class);
HttpEntity<MappingJacksonValueHolder> entity = new HttpEntity<MappingJacksonValueHolder>(jsv);
MappingJacksonValue jsv = new MappingJacksonValue(bean, MyJacksonView1.class);
HttpEntity<MappingJacksonValue> entity = new HttpEntity<MappingJacksonValue>(jsv);
String s = template.postForObject(baseUrl + "/jsonpost", entity, String.class, "post");
assertTrue(s.contains("\"with1\":\"with\""));
assertFalse(s.contains("\"with2\":\"with\""));