Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
项羽过江东
spring-framework-source
提交
2f43f77d
spring-framework-source
项目概览
项羽过江东
/
spring-framework-source
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
spring-framework-source
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2f43f77d
编写于
10月 02, 2021
作者:
S
Sam Kruglov
提交者:
Sébastien Deleuze
8月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add ParameterNamesModule to "well known" jackson modules
See gh-27511
上级
f054c2e8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
35 addition
and
0 deletion
+35
-0
spring-web/spring-web.gradle
spring-web/spring-web.gradle
+1
-0
spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java
...work/http/converter/json/Jackson2ObjectMapperBuilder.java
+10
-0
spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java
...http/converter/json/Jackson2ObjectMapperBuilderTests.java
+24
-0
未找到文件。
spring-web/spring-web.gradle
浏览文件 @
2f43f77d
...
...
@@ -81,6 +81,7 @@ dependencies {
testImplementation
(
"com.fasterxml.jackson.datatype:jackson-datatype-jdk8"
)
testImplementation
(
"com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
)
testImplementation
(
"com.fasterxml.jackson.module:jackson-module-kotlin"
)
testImplementation
(
"com.fasterxml.jackson.module:jackson-module-parameter-names"
)
testImplementation
(
"com.squareup.okhttp3:mockwebserver"
)
testImplementation
(
"io.micrometer:micrometer-observation-test"
)
testImplementation
(
"io.projectreactor:reactor-test"
)
...
...
spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java
浏览文件 @
2f43f77d
...
...
@@ -859,6 +859,16 @@ public class Jackson2ObjectMapperBuilder {
// jackson-datatype-jdk8 not available
}
try
{
Class
<?
extends
Module
>
parameterNamesModuleClass
=
(
Class
<?
extends
Module
>)
ClassUtils
.
forName
(
"com.fasterxml.jackson.module.paramnames.ParameterNamesModule"
,
this
.
moduleClassLoader
);
Module
parameterNamesModule
=
BeanUtils
.
instantiateClass
(
parameterNamesModuleClass
);
modulesToRegister
.
set
(
parameterNamesModule
.
getTypeId
(),
parameterNamesModule
);
}
catch
(
ClassNotFoundException
ex
)
{
// jackson-module-parameter-names not available
}
try
{
Class
<?
extends
Module
>
javaTimeModuleClass
=
(
Class
<?
extends
Module
>)
ClassUtils
.
forName
(
"com.fasterxml.jackson.datatype.jsr310.JavaTimeModule"
,
this
.
moduleClassLoader
);
...
...
spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java
浏览文件 @
2f43f77d
...
...
@@ -85,6 +85,8 @@ import org.springframework.http.ProblemDetail;
import
org.springframework.util.StringUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatCode
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalArgumentException
;
/**
...
...
@@ -255,6 +257,25 @@ class Jackson2ObjectMapperBuilderTests {
assertThat
(
serializers
.
findSerializer
(
null
,
SimpleType
.
construct
(
Integer
.
class
),
null
).
getClass
()).
isSameAs
(
CustomIntegerSerializer
.
class
);
}
static
class
ParameterModuleDto
{
int
x
;
int
y
;
ParameterModuleDto
(
int
x
,
int
y
)
{
this
.
x
=
x
;
this
.
y
=
y
;
}
int
getX
()
{
return
x
;
}
int
getY
()
{
return
y
;
}
}
@Test
void
wellKnownModules
()
throws
JsonProcessingException
,
UnsupportedEncodingException
{
ObjectMapper
objectMapper
=
Jackson2ObjectMapperBuilder
.
json
().
build
();
...
...
@@ -265,6 +286,9 @@ class Jackson2ObjectMapperBuilderTests {
Optional
<
String
>
optional
=
Optional
.
of
(
"test"
);
assertThat
(
new
String
(
objectMapper
.
writeValueAsBytes
(
optional
),
"UTF-8"
)).
isEqualTo
(
"\"test\""
);
assertThatCode
(()
->
objectMapper
.
readValue
(
"{\"x\":1,\"y\":2}"
,
ParameterModuleDto
.
class
)).
doesNotThrowAnyException
();
// Kotlin module
IntRange
range
=
new
IntRange
(
1
,
3
);
assertThat
(
new
String
(
objectMapper
.
writeValueAsBytes
(
range
),
"UTF-8"
)).
isEqualTo
(
"{\"start\":1,\"end\":3}"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录