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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user