Complete set of constructors with consistent javadoc
Closes gh-31234
This commit is contained in:
parent
e42e89c04f
commit
aa1360b154
|
@ -89,6 +89,9 @@ public class MappingJackson2MessageConverter implements SmartMessageConverter, B
|
||||||
private ClassLoader beanClassLoader;
|
private ClassLoader beanClassLoader;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a {@code MappingJackson2MessageConverter} with a default {@link ObjectMapper}.
|
||||||
|
*/
|
||||||
@SuppressWarnings("deprecation") // on Jackson 2.13: configure(MapperFeature, boolean)
|
@SuppressWarnings("deprecation") // on Jackson 2.13: configure(MapperFeature, boolean)
|
||||||
public MappingJackson2MessageConverter() {
|
public MappingJackson2MessageConverter() {
|
||||||
this.objectMapper = new ObjectMapper();
|
this.objectMapper = new ObjectMapper();
|
||||||
|
@ -96,13 +99,20 @@ public class MappingJackson2MessageConverter implements SmartMessageConverter, B
|
||||||
this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a {@code MappingJackson2MessageConverter} with a custom {@link ObjectMapper}.
|
||||||
|
* @param objectMapper the ObjectMapper to use
|
||||||
|
* @since 6.1
|
||||||
|
*/
|
||||||
public MappingJackson2MessageConverter(ObjectMapper objectMapper) {
|
public MappingJackson2MessageConverter(ObjectMapper objectMapper) {
|
||||||
Assert.notNull(objectMapper, "ObjectMapper must not be null");
|
Assert.notNull(objectMapper, "ObjectMapper must not be null");
|
||||||
this.objectMapper = objectMapper;
|
this.objectMapper = objectMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the {@link ObjectMapper} to use instead of using the default.
|
* Set the {@code ObjectMapper} for this converter.
|
||||||
|
* If not set, a default {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
|
||||||
*/
|
*/
|
||||||
public void setObjectMapper(ObjectMapper objectMapper) {
|
public void setObjectMapper(ObjectMapper objectMapper) {
|
||||||
Assert.notNull(objectMapper, "ObjectMapper must not be null");
|
Assert.notNull(objectMapper, "ObjectMapper must not be null");
|
||||||
|
|
|
@ -59,6 +59,9 @@ import org.springframework.util.MimeType;
|
||||||
*/
|
*/
|
||||||
public class MappingJackson2MessageConverter extends AbstractMessageConverter {
|
public class MappingJackson2MessageConverter extends AbstractMessageConverter {
|
||||||
|
|
||||||
|
private static final MimeType[] DEFAULT_MIME_TYPES = new MimeType[] {
|
||||||
|
new MimeType("application", "json"), new MimeType("application", "*+json")};
|
||||||
|
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -66,41 +69,51 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a {@code MappingJackson2MessageConverter} supporting
|
* Construct a {@code MappingJackson2MessageConverter} with a default {@link ObjectMapper},
|
||||||
* the {@code application/json} MIME type with {@code UTF-8} character set.
|
* supporting the {@code application/json} MIME type with {@code UTF-8} character set.
|
||||||
*/
|
*/
|
||||||
public MappingJackson2MessageConverter() {
|
public MappingJackson2MessageConverter() {
|
||||||
super(new MimeType("application", "json"), new MimeType("application", "*+json"));
|
this(DEFAULT_MIME_TYPES);
|
||||||
this.objectMapper = initObjectMapper();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a {@code MappingJackson2MessageConverter} supporting
|
* Construct a {@code MappingJackson2MessageConverter} with a default {@link ObjectMapper},
|
||||||
* one or more custom MIME types.
|
* supporting one or more custom MIME types.
|
||||||
* @param supportedMimeTypes the supported MIME types
|
* @param supportedMimeTypes the supported MIME types
|
||||||
* @since 4.1.5
|
* @since 4.1.5
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation") // on Jackson 2.13: configure(MapperFeature, boolean)
|
||||||
public MappingJackson2MessageConverter(MimeType... supportedMimeTypes) {
|
public MappingJackson2MessageConverter(MimeType... supportedMimeTypes) {
|
||||||
super(supportedMimeTypes);
|
super(supportedMimeTypes);
|
||||||
this.objectMapper = initObjectMapper();
|
this.objectMapper = new ObjectMapper();
|
||||||
|
this.objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
|
||||||
|
this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a {@code MappingJackson2MessageConverter} with a custom {@link ObjectMapper},
|
||||||
|
* supporting the {@code application/json} MIME type with {@code UTF-8} character set.
|
||||||
|
* @param objectMapper the ObjectMapper to use
|
||||||
|
* @since 6.1
|
||||||
|
*/
|
||||||
public MappingJackson2MessageConverter(ObjectMapper objectMapper) {
|
public MappingJackson2MessageConverter(ObjectMapper objectMapper) {
|
||||||
super(new MimeType("application", "json"), new MimeType("application", "*+json"));
|
this(objectMapper, DEFAULT_MIME_TYPES);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a {@code MappingJackson2MessageConverter} with a custom {@link ObjectMapper},
|
||||||
|
* supporting one or more custom MIME types.
|
||||||
|
* @param objectMapper the ObjectMapper to use
|
||||||
|
* @param supportedMimeTypes the supported MIME types
|
||||||
|
* @since 6.1
|
||||||
|
*/
|
||||||
|
public MappingJackson2MessageConverter(ObjectMapper objectMapper, MimeType... supportedMimeTypes) {
|
||||||
|
super(supportedMimeTypes);
|
||||||
Assert.notNull(objectMapper, "ObjectMapper must not be null");
|
Assert.notNull(objectMapper, "ObjectMapper must not be null");
|
||||||
this.objectMapper = objectMapper;
|
this.objectMapper = objectMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") // on Jackson 2.13: configure(MapperFeature, boolean)
|
|
||||||
private ObjectMapper initObjectMapper() {
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
|
|
||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
return objectMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the {@code ObjectMapper} for this converter.
|
* Set the {@code ObjectMapper} for this converter.
|
||||||
* If not set, a default {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
|
* If not set, a default {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
|
||||||
|
|
Loading…
Reference in New Issue