Add parametrized constructors to MappingJackson2MessageConverter

Issue: SPR-12724
(cherry picked from commit 8159aa9)
This commit is contained in:
Sebastien Deleuze
2015-02-18 12:32:04 +01:00
committed by Juergen Hoeller
parent 2a240b0dc8
commit 1dc39324b9
2 changed files with 63 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.core.JsonEncoding;
@@ -51,6 +52,7 @@ import org.springframework.util.MimeType;
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @author Sebastien Deleuze
* @since 4.0
*/
public class MappingJackson2MessageConverter extends AbstractMessageConverter {
@@ -65,8 +67,28 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
private Boolean prettyPrint;
/**
* Construct a {@code MappingJackson2MessageConverter} supporting
* the {@code application/json} MIME type.
*/
public MappingJackson2MessageConverter() {
super(new MimeType("application", "json", Charset.forName("UTF-8")));
initObjectMapper();
}
/**
* Construct a {@code MappingJackson2MessageConverter} supporting
* one or more custom MIME types.
* @param supportedMimeTypes the supported MIME types
* @since 4.1.5
*/
public MappingJackson2MessageConverter(MimeType... supportedMimeTypes) {
super(Arrays.asList(supportedMimeTypes));
initObjectMapper();
}
private void initObjectMapper() {
this.objectMapper = new ObjectMapper();
this.objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);