Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
77abe078
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
77abe078
编写于
9月 30, 2014
作者:
S
Sebastien Deleuze
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Set Jackson DEFAULT_VIEW_INCLUSION property to false by default
Issue: SPR-12179
上级
42aef5f5
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
35 addition
and
17 deletion
+35
-17
spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java
...work/http/converter/json/Jackson2ObjectMapperBuilder.java
+9
-0
spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.java
.../http/converter/json/Jackson2ObjectMapperFactoryBean.java
+9
-0
spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java
...http/converter/json/Jackson2ObjectMapperBuilderTests.java
+2
-2
spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBeanTests.java
.../converter/json/Jackson2ObjectMapperFactoryBeanTests.java
+1
-1
spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java
...verter/json/MappingJackson2HttpMessageConverterTests.java
+2
-2
spring-web/src/test/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverterTests.java
...rter/xml/MappingJackson2XmlHttpMessageConverterTests.java
+1
-1
spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java
...ingframework/web/client/RestTemplateIntegrationTests.java
+1
-1
spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java
...springframework/web/servlet/config/MvcNamespaceTests.java
+2
-2
spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java
.../annotation/WebMvcConfigurationSupportExtensionTests.java
+2
-2
spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportTests.java
...et/config/annotation/WebMvcConfigurationSupportTests.java
+2
-2
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java
...d/annotation/RequestResponseBodyMethodProcessorTests.java
+4
-4
未找到文件。
spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java
浏览文件 @
77abe078
...
...
@@ -47,6 +47,12 @@ import org.springframework.util.ClassUtils;
/**
* A builder used to create {@link ObjectMapper} instances with a fluent API.
*
* <p>It customizes Jackson defaults properties with the following ones:
* <ul>
* <li>{@link MapperFeature#DEFAULT_VIEW_INCLUSION} is disabled</li>
* <li>{@link DeserializationFeature#FAIL_ON_UNKNOWN_PROPERTIES} is disabled</li>
* </ul>
*
* <p>Note that Jackson's JSR-310 and Joda-Time support modules will be registered automatically
* when available (and when Java 8 and Joda-Time themselves are available, respectively).
*
...
...
@@ -384,6 +390,9 @@ public class Jackson2ObjectMapperBuilder {
this
.
objectMapper
.
registerModule
(
module
);
}
if
(!
features
.
containsKey
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
))
{
configureFeature
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
,
false
);
}
if
(!
features
.
containsKey
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
))
{
configureFeature
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
}
...
...
spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.java
浏览文件 @
77abe078
...
...
@@ -52,6 +52,12 @@ import org.springframework.util.ClassUtils;
* {@link XmlMapper} ({@code createXmlMapper} property set to true) with setters
* to enable or disable Jackson features from within XML configuration.
*
* <p>It customizes Jackson defaults properties with the following ones:
* <ul>
* <li>{@link MapperFeature#DEFAULT_VIEW_INCLUSION} is disabled</li>
* <li>{@link DeserializationFeature#FAIL_ON_UNKNOWN_PROPERTIES} is disabled</li>
* </ul>
*
* <p>Example usage with
* {@link MappingJackson2HttpMessageConverter}:
*
...
...
@@ -413,6 +419,9 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
this
.
objectMapper
.
registerModule
(
module
);
}
if
(!
features
.
containsKey
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
))
{
configureFeature
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
,
false
);
}
if
(!
features
.
containsKey
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
))
{
configureFeature
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
}
...
...
spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java
浏览文件 @
77abe078
...
...
@@ -80,7 +80,7 @@ public class Jackson2ObjectMapperBuilderTests {
public
void
defaultProperties
()
{
ObjectMapper
objectMapper
=
Jackson2ObjectMapperBuilder
.
json
().
build
();
assertNotNull
(
objectMapper
);
assert
Tru
e
(
objectMapper
.
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assert
Fals
e
(
objectMapper
.
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assertFalse
(
objectMapper
.
isEnabled
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
));
assertTrue
(
objectMapper
.
isEnabled
(
MapperFeature
.
AUTO_DETECT_FIELDS
));
assertTrue
(
objectMapper
.
isEnabled
(
MapperFeature
.
AUTO_DETECT_GETTERS
));
...
...
@@ -240,7 +240,7 @@ public class Jackson2ObjectMapperBuilderTests {
assertTrue
(
objectMapper
.
getFactory
().
isEnabled
(
JsonGenerator
.
Feature
.
WRITE_NUMBERS_AS_STRINGS
));
assertFalse
(
objectMapper
.
getSerializationConfig
().
isEnabled
(
MapperFeature
.
AUTO_DETECT_GETTERS
));
assert
Tru
e
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assert
Fals
e
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assertFalse
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
));
assertFalse
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
MapperFeature
.
AUTO_DETECT_FIELDS
));
assertFalse
(
objectMapper
.
getFactory
().
isEnabled
(
JsonParser
.
Feature
.
AUTO_CLOSE_SOURCE
));
...
...
spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBeanTests.java
浏览文件 @
77abe078
...
...
@@ -259,7 +259,7 @@ public class Jackson2ObjectMapperFactoryBeanTests {
assertTrue
(
objectMapper
.
getFactory
().
isEnabled
(
JsonGenerator
.
Feature
.
WRITE_NUMBERS_AS_STRINGS
));
assertFalse
(
objectMapper
.
getSerializationConfig
().
isEnabled
(
MapperFeature
.
AUTO_DETECT_GETTERS
));
assert
Tru
e
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assert
Fals
e
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assertFalse
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
));
assertFalse
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
MapperFeature
.
AUTO_DETECT_FIELDS
));
assertFalse
(
objectMapper
.
getFactory
().
isEnabled
(
JsonParser
.
Feature
.
AUTO_CLOSE_SOURCE
));
...
...
spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java
浏览文件 @
77abe078
...
...
@@ -255,7 +255,7 @@ public class MappingJackson2HttpMessageConverterTests {
String
result
=
outputMessage
.
getBodyAsString
(
Charset
.
forName
(
"UTF-8"
));
assertThat
(
result
,
containsString
(
"\"withView1\":\"with\""
));
assertThat
(
result
,
not
(
containsString
(
"\"withView2\":\"with\""
)));
assertThat
(
result
,
containsString
(
"\"withoutView\":\"without\""
));
assertThat
(
result
,
not
(
containsString
(
"\"withoutView\":\"without\""
)
));
}
@Test
...
...
@@ -288,7 +288,7 @@ public class MappingJackson2HttpMessageConverterTests {
assertThat
(
result
,
endsWith
(
");"
));
assertThat
(
result
,
containsString
(
"\"withView1\":\"with\""
));
assertThat
(
result
,
not
(
containsString
(
"\"withView2\":\"with\""
)));
assertThat
(
result
,
containsString
(
"\"withoutView\":\"without\""
));
assertThat
(
result
,
not
(
containsString
(
"\"withoutView\":\"without\""
)
));
}
...
...
spring-web/src/test/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverterTests.java
浏览文件 @
77abe078
...
...
@@ -126,7 +126,7 @@ public class MappingJackson2XmlHttpMessageConverterTests {
String
result
=
outputMessage
.
getBodyAsString
(
Charset
.
forName
(
"UTF-8"
));
assertThat
(
result
,
containsString
(
"<withView1>with</withView1>"
));
assertThat
(
result
,
not
(
containsString
(
"<withView2>with</withView2>"
)));
assertThat
(
result
,
containsString
(
"<withoutView>without</withoutView>"
));
assertThat
(
result
,
not
(
containsString
(
"<withoutView>without</withoutView>"
)
));
}
@Test
...
...
spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java
浏览文件 @
77abe078
...
...
@@ -226,7 +226,7 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
String
s
=
template
.
postForObject
(
baseUrl
+
"/jsonpost"
,
entity
,
String
.
class
,
"post"
);
assertTrue
(
s
.
contains
(
"\"with1\":\"with\""
));
assertFalse
(
s
.
contains
(
"\"with2\":\"with\""
));
assert
Tru
e
(
s
.
contains
(
"\"without\":\"without\""
));
assert
Fals
e
(
s
.
contains
(
"\"without\":\"without\""
));
}
// SPR-12123
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java
浏览文件 @
77abe078
...
...
@@ -173,8 +173,8 @@ public class MvcNamespaceTests {
for
(
HttpMessageConverter
<?>
converter
:
converters
)
{
if
(
converter
instanceof
AbstractJackson2HttpMessageConverter
)
{
ObjectMapper
objectMapper
=
((
AbstractJackson2HttpMessageConverter
)
converter
).
getObjectMapper
();
assert
Tru
e
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assert
Tru
e
(
objectMapper
.
getSerializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assert
Fals
e
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assert
Fals
e
(
objectMapper
.
getSerializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assertFalse
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
));
if
(
converter
instanceof
MappingJackson2XmlHttpMessageConverter
)
{
assertEquals
(
XmlMapper
.
class
,
objectMapper
.
getClass
());
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java
浏览文件 @
77abe078
...
...
@@ -162,8 +162,8 @@ public class WebMvcConfigurationSupportExtensionTests {
assertEquals
(
1
,
adapter
.
getMessageConverters
().
size
());
assertEquals
(
MappingJackson2HttpMessageConverter
.
class
,
adapter
.
getMessageConverters
().
get
(
0
).
getClass
());
ObjectMapper
objectMapper
=
((
MappingJackson2HttpMessageConverter
)
adapter
.
getMessageConverters
().
get
(
0
)).
getObjectMapper
();
assert
Tru
e
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assert
Tru
e
(
objectMapper
.
getSerializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assert
Fals
e
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assert
Fals
e
(
objectMapper
.
getSerializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assertFalse
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
));
DirectFieldAccessor
fieldAccessor
=
new
DirectFieldAccessor
(
adapter
);
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportTests.java
浏览文件 @
77abe078
...
...
@@ -162,8 +162,8 @@ public class WebMvcConfigurationSupportTests {
for
(
HttpMessageConverter
<?>
converter
:
converters
)
{
if
(
converter
instanceof
AbstractJackson2HttpMessageConverter
)
{
ObjectMapper
objectMapper
=
((
AbstractJackson2HttpMessageConverter
)
converter
).
getObjectMapper
();
assert
Tru
e
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assert
Tru
e
(
objectMapper
.
getSerializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assert
Fals
e
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assert
Fals
e
(
objectMapper
.
getSerializationConfig
().
isEnabled
(
MapperFeature
.
DEFAULT_VIEW_INCLUSION
));
assertFalse
(
objectMapper
.
getDeserializationConfig
().
isEnabled
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
));
if
(
converter
instanceof
MappingJackson2XmlHttpMessageConverter
)
{
assertEquals
(
XmlMapper
.
class
,
objectMapper
.
getClass
());
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java
浏览文件 @
77abe078
...
...
@@ -322,7 +322,7 @@ public class RequestResponseBodyMethodProcessorTests {
String
content
=
this
.
servletResponse
.
getContentAsString
();
assertFalse
(
content
.
contains
(
"\"withView1\":\"with\""
));
assertTrue
(
content
.
contains
(
"\"withView2\":\"with\""
));
assert
Tru
e
(
content
.
contains
(
"\"withoutView\":\"without\""
));
assert
Fals
e
(
content
.
contains
(
"\"withoutView\":\"without\""
));
}
@Test
...
...
@@ -343,7 +343,7 @@ public class RequestResponseBodyMethodProcessorTests {
String
content
=
this
.
servletResponse
.
getContentAsString
();
assertFalse
(
content
.
contains
(
"\"withView1\":\"with\""
));
assertTrue
(
content
.
contains
(
"\"withView2\":\"with\""
));
assert
Tru
e
(
content
.
contains
(
"\"withoutView\":\"without\""
));
assert
Fals
e
(
content
.
contains
(
"\"withoutView\":\"without\""
));
}
// SPR-12149
...
...
@@ -366,7 +366,7 @@ public class RequestResponseBodyMethodProcessorTests {
String
content
=
this
.
servletResponse
.
getContentAsString
();
assertFalse
(
content
.
contains
(
"<withView1>with</withView1>"
));
assertTrue
(
content
.
contains
(
"<withView2>with</withView2>"
));
assert
Tru
e
(
content
.
contains
(
"<withoutView>without</withoutView>"
));
assert
Fals
e
(
content
.
contains
(
"<withoutView>without</withoutView>"
));
}
// SPR-12149
...
...
@@ -389,7 +389,7 @@ public class RequestResponseBodyMethodProcessorTests {
String
content
=
this
.
servletResponse
.
getContentAsString
();
assertFalse
(
content
.
contains
(
"<withView1>with</withView1>"
));
assertTrue
(
content
.
contains
(
"<withView2>with</withView2>"
));
assert
Tru
e
(
content
.
contains
(
"<withoutView>without</withoutView>"
));
assert
Fals
e
(
content
.
contains
(
"<withoutView>without</withoutView>"
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录