Add an ObjectMapper constructor to MappingJackson2(Json|Xml)View

Instead of having to use the default constructor then calling
setObjectMapper(ObjectMapper), these constructors allow
MappingJackson2JsonView and MappingJackson2XmlView to be created and
configured with the desired object mapper in one step.
This commit is contained in:
Sebastien Deleuze
2015-08-19 14:04:15 +02:00
parent ddd6c9bea0
commit d4c74ad346
3 changed files with 18 additions and 1 deletions

View File

@@ -61,7 +61,7 @@ public abstract class AbstractJackson2View extends AbstractView {
protected AbstractJackson2View(ObjectMapper objectMapper, String contentType) {
this.objectMapper = objectMapper;
setObjectMapper(objectMapper);
setContentType(contentType);
setExposePathVariables(false);
}

View File

@@ -88,6 +88,15 @@ public class MappingJackson2JsonView extends AbstractJackson2View {
super(Jackson2ObjectMapperBuilder.json().build(), DEFAULT_CONTENT_TYPE);
}
/**
* Construct a new {@code MappingJackson2JsonView} using the provided
* {@link ObjectMapper} and setting the content type to {@code application/json}.
* @since 4.2.1
*/
public MappingJackson2JsonView(ObjectMapper objectMapper) {
super(objectMapper, DEFAULT_CONTENT_TYPE);
}
/**
* Specify a custom prefix to use for this view's JSON output.

View File

@@ -58,6 +58,14 @@ public class MappingJackson2XmlView extends AbstractJackson2View {
super(Jackson2ObjectMapperBuilder.xml().build(), DEFAULT_CONTENT_TYPE);
}
/**
* Construct a new {@code MappingJackson2XmlView} using the provided {@link XmlMapper}
* and setting the content type to {@code application/xml}.
* @since 4.2.1
*/
public MappingJackson2XmlView(XmlMapper xmlMapper) {
super(xmlMapper, DEFAULT_CONTENT_TYPE);
}
/**
* {@inheritDoc}