File tree Expand file tree Collapse file tree 3 files changed +10
-7
lines changed
spring-web/src/main/java/org/springframework/http/codec/json Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 35
35
import org .springframework .core .ResolvableType ;
36
36
import org .springframework .util .Assert ;
37
37
import org .springframework .util .MimeType ;
38
+ import org .springframework .util .ObjectUtils ;
38
39
39
40
/**
40
41
* Base class providing support methods for Jackson 2.9 encoding and decoding.
@@ -62,19 +63,21 @@ public abstract class Jackson2CodecSupport {
62
63
63
64
protected final ObjectMapper objectMapper ;
64
65
66
+ private final List <MimeType > mimeTypes ;
67
+
65
68
66
69
/**
67
70
* Constructor with a Jackson {@link ObjectMapper} to use.
68
71
*/
69
- protected Jackson2CodecSupport (ObjectMapper objectMapper ) {
72
+ protected Jackson2CodecSupport (ObjectMapper objectMapper , MimeType ... mimeTypes ) {
70
73
Assert .notNull (objectMapper , "ObjectMapper must not be null" );
71
74
this .objectMapper = objectMapper ;
75
+ this .mimeTypes = !ObjectUtils .isEmpty (mimeTypes ) ? Arrays .asList (mimeTypes ) : JSON_MIME_TYPES ;
72
76
}
73
77
74
78
75
79
protected boolean supportsMimeType (MimeType mimeType ) {
76
- return (mimeType == null ||
77
- JSON_MIME_TYPES .stream ().anyMatch (m -> m .isCompatibleWith (mimeType )));
80
+ return (mimeType == null || this .mimeTypes .stream ().anyMatch (m -> m .isCompatibleWith (mimeType )));
78
81
}
79
82
80
83
protected JavaType getJavaType (Type type , Class <?> contextClass ) {
Original file line number Diff line number Diff line change @@ -61,8 +61,8 @@ public Jackson2JsonDecoder() {
61
61
super (Jackson2ObjectMapperBuilder .json ().build ());
62
62
}
63
63
64
- public Jackson2JsonDecoder (ObjectMapper mapper ) {
65
- super (mapper );
64
+ public Jackson2JsonDecoder (ObjectMapper mapper , MimeType ... mimeTypes ) {
65
+ super (mapper , mimeTypes );
66
66
}
67
67
68
68
Original file line number Diff line number Diff line change @@ -71,8 +71,8 @@ public Jackson2JsonEncoder() {
71
71
this (Jackson2ObjectMapperBuilder .json ().build ());
72
72
}
73
73
74
- public Jackson2JsonEncoder (ObjectMapper mapper ) {
75
- super (mapper );
74
+ public Jackson2JsonEncoder (ObjectMapper mapper , MimeType ... mimeTypes ) {
75
+ super (mapper , mimeTypes );
76
76
this .streamingMediaTypes .add (MediaType .APPLICATION_STREAM_JSON );
77
77
this .ssePrettyPrinter = initSsePrettyPrinter ();
78
78
}
You can’t perform that action at this time.
0 commit comments