Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
eb971690
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 搜索 >>
提交
eb971690
编写于
4月 09, 2019
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '5.1.x'
上级
604361ee
2835424f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
16 deletion
+19
-16
spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java
...ingframework/http/codec/json/AbstractJackson2Decoder.java
+2
-2
spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java
...rg/springframework/http/codec/json/Jackson2Tokenizer.java
+10
-2
spring-web/src/test/java/org/springframework/http/codec/json/Jackson2TokenizerTests.java
...ringframework/http/codec/json/Jackson2TokenizerTests.java
+7
-12
未找到文件。
spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java
浏览文件 @
eb971690
...
...
@@ -87,7 +87,7 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
@Nullable
MimeType
mimeType
,
@Nullable
Map
<
String
,
Object
>
hints
)
{
Flux
<
TokenBuffer
>
tokens
=
Jackson2Tokenizer
.
tokenize
(
Flux
.
from
(
input
),
this
.
jsonFactory
,
getObjectMapper
()
.
getDeserializationContext
()
,
true
);
Flux
.
from
(
input
),
this
.
jsonFactory
,
getObjectMapper
(),
true
);
return
decodeInternal
(
tokens
,
elementType
,
mimeType
,
hints
);
}
...
...
@@ -96,7 +96,7 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
@Nullable
MimeType
mimeType
,
@Nullable
Map
<
String
,
Object
>
hints
)
{
Flux
<
TokenBuffer
>
tokens
=
Jackson2Tokenizer
.
tokenize
(
Flux
.
from
(
input
),
this
.
jsonFactory
,
getObjectMapper
()
.
getDeserializationContext
()
,
false
);
Flux
.
from
(
input
),
this
.
jsonFactory
,
getObjectMapper
(),
false
);
return
decodeInternal
(
tokens
,
elementType
,
mimeType
,
hints
).
singleOrEmpty
();
}
...
...
spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java
浏览文件 @
eb971690
...
...
@@ -27,6 +27,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import
com.fasterxml.jackson.core.JsonToken
;
import
com.fasterxml.jackson.core.async.ByteArrayFeeder
;
import
com.fasterxml.jackson.databind.DeserializationContext
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.deser.DefaultDeserializationContext
;
import
com.fasterxml.jackson.databind.util.TokenBuffer
;
import
reactor.core.Exceptions
;
import
reactor.core.publisher.Flux
;
...
...
@@ -177,16 +179,22 @@ final class Jackson2Tokenizer {
* Tokenize the given {@code Flux<DataBuffer>} into {@code Flux<TokenBuffer>}.
* @param dataBuffers the source data buffers
* @param jsonFactory the factory to use
* @param objectMapper the current mapper instance
* @param tokenizeArrayElements if {@code true} and the "top level" JSON object is
* an array, each element is returned individually immediately after it is received
* @return the resulting token buffers
*/
public
static
Flux
<
TokenBuffer
>
tokenize
(
Flux
<
DataBuffer
>
dataBuffers
,
JsonFactory
jsonFactory
,
DeserializationContext
deserializationContext
,
boolean
tokenizeArrayElements
)
{
ObjectMapper
objectMapper
,
boolean
tokenizeArrayElements
)
{
try
{
JsonParser
parser
=
jsonFactory
.
createNonBlockingByteArrayParser
();
Jackson2Tokenizer
tokenizer
=
new
Jackson2Tokenizer
(
parser
,
deserializationContext
,
tokenizeArrayElements
);
DeserializationContext
context
=
objectMapper
.
getDeserializationContext
();
if
(
context
instanceof
DefaultDeserializationContext
)
{
context
=
((
DefaultDeserializationContext
)
context
).
createInstance
(
objectMapper
.
getDeserializationConfig
(),
parser
,
objectMapper
.
getInjectableValues
());
}
Jackson2Tokenizer
tokenizer
=
new
Jackson2Tokenizer
(
parser
,
context
,
tokenizeArrayElements
);
return
dataBuffers
.
concatMapIterable
(
tokenizer:
:
tokenize
).
concatWith
(
tokenizer
.
endOfInput
());
}
catch
(
IOException
ex
)
{
...
...
spring-web/src/test/java/org/springframework/http/codec/json/Jackson2TokenizerTests.java
浏览文件 @
eb971690
...
...
@@ -184,22 +184,18 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
@Test
public
void
errorInStream
()
{
DataBuffer
buffer
=
stringBuffer
(
"{\"id\":1,\"name\":"
);
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
buffer
)
.
concatWith
(
Flux
.
error
(
new
RuntimeException
()));
Flux
<
TokenBuffer
>
result
=
Jackson2Tokenizer
.
tokenize
(
source
,
this
.
jsonFactory
,
this
.
objectMapper
.
getDeserializationContext
(),
true
);
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
buffer
).
concatWith
(
Flux
.
error
(
new
RuntimeException
()));
Flux
<
TokenBuffer
>
result
=
Jackson2Tokenizer
.
tokenize
(
source
,
this
.
jsonFactory
,
this
.
objectMapper
,
true
);
StepVerifier
.
create
(
result
)
.
expectError
(
RuntimeException
.
class
)
.
verify
();
}
@Test
// SPR-16521
@Test
// SPR-16521
public
void
jsonEOFExceptionIsWrappedAsDecodingError
()
{
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
"{\"status\": \"noClosingQuote}"
));
Flux
<
TokenBuffer
>
tokens
=
Jackson2Tokenizer
.
tokenize
(
source
,
this
.
jsonFactory
,
this
.
objectMapper
.
getDeserializationContext
(),
false
);
Flux
<
TokenBuffer
>
tokens
=
Jackson2Tokenizer
.
tokenize
(
source
,
this
.
jsonFactory
,
this
.
objectMapper
,
false
);
StepVerifier
.
create
(
tokens
)
.
expectError
(
DecodingException
.
class
)
...
...
@@ -208,12 +204,11 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
private
void
testTokenize
(
List
<
String
>
source
,
List
<
String
>
expected
,
boolean
tokenizeArrayElements
)
{
Flux
<
TokenBuffer
>
token
BufferFlux
=
Jackson2Tokenizer
.
tokenize
(
Flux
<
TokenBuffer
>
token
s
=
Jackson2Tokenizer
.
tokenize
(
Flux
.
fromIterable
(
source
).
map
(
this
::
stringBuffer
),
this
.
jsonFactory
,
this
.
objectMapper
.
getDeserializationContext
(),
tokenizeArrayElements
);
this
.
jsonFactory
,
this
.
objectMapper
,
tokenizeArrayElements
);
Flux
<
String
>
result
=
token
BufferFlux
Flux
<
String
>
result
=
token
s
.
map
(
tokenBuffer
->
{
try
{
TreeNode
root
=
this
.
objectMapper
.
readTree
(
tokenBuffer
.
asParser
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录