Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
b91867cf
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 搜索 >>
提交
b91867cf
编写于
9月 12, 2016
作者:
S
Sebastien Deleuze
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update Codec API to use Map<String, Object> for hints
Issue: SPR-14557
上级
b88ed859
变更
32
隐藏空白更改
内联
并排
Showing
32 changed file
with
212 addition
and
173 deletion
+212
-173
spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java
.../java/org/springframework/core/codec/AbstractDecoder.java
+3
-2
spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java
.../java/org/springframework/core/codec/AbstractEncoder.java
+2
-1
spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java
...pringframework/core/codec/AbstractSingleValueEncoder.java
+5
-3
spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java
...ava/org/springframework/core/codec/ByteBufferDecoder.java
+3
-2
spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java
...ava/org/springframework/core/codec/ByteBufferEncoder.java
+3
-2
spring-core/src/main/java/org/springframework/core/codec/CharSequenceEncoder.java
...a/org/springframework/core/codec/CharSequenceEncoder.java
+3
-2
spring-core/src/main/java/org/springframework/core/codec/Decoder.java
...src/main/java/org/springframework/core/codec/Decoder.java
+8
-6
spring-core/src/main/java/org/springframework/core/codec/Encoder.java
...src/main/java/org/springframework/core/codec/Encoder.java
+6
-4
spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java
.../java/org/springframework/core/codec/ResourceDecoder.java
+3
-2
spring-core/src/main/java/org/springframework/core/codec/ResourceEncoder.java
.../java/org/springframework/core/codec/ResourceEncoder.java
+3
-2
spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java
...in/java/org/springframework/core/codec/StringDecoder.java
+4
-3
spring-core/src/test/java/org/springframework/core/codec/ByteBufferDecoderTests.java
...rg/springframework/core/codec/ByteBufferDecoderTests.java
+8
-4
spring-core/src/test/java/org/springframework/core/codec/ByteBufferEncoderTests.java
...rg/springframework/core/codec/ByteBufferEncoderTests.java
+8
-4
spring-core/src/test/java/org/springframework/core/codec/CharSequenceEncoderTests.java
.../springframework/core/codec/CharSequenceEncoderTests.java
+14
-7
spring-core/src/test/java/org/springframework/core/codec/ResourceDecoderTests.java
.../org/springframework/core/codec/ResourceDecoderTests.java
+10
-9
spring-core/src/test/java/org/springframework/core/codec/ResourceEncoderTests.java
.../org/springframework/core/codec/ResourceEncoderTests.java
+10
-9
spring-core/src/test/java/org/springframework/core/codec/StringDecoderTests.java
...va/org/springframework/core/codec/StringDecoderTests.java
+24
-11
spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/HttpMessageWriterView.java
...ework/web/reactive/result/view/HttpMessageWriterView.java
+6
-4
spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java
...tion/RequestMappingMessageConversionIntegrationTests.java
+2
-1
spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Codec.java
...pringframework/http/codec/json/AbstractJackson2Codec.java
+2
-0
spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonDecoder.java
.../springframework/http/codec/json/Jackson2JsonDecoder.java
+8
-12
spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonEncoder.java
.../springframework/http/codec/json/Jackson2JsonEncoder.java
+10
-17
spring-web/src/main/java/org/springframework/http/codec/json/JsonObjectDecoder.java
...rg/springframework/http/codec/json/JsonObjectDecoder.java
+2
-1
spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java
...a/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java
+4
-3
spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlEncoder.java
...a/org/springframework/http/codec/xml/Jaxb2XmlEncoder.java
+3
-2
spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java
...a/org/springframework/http/codec/xml/XmlEventDecoder.java
+2
-1
spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java
...ngframework/http/codec/json/Jackson2JsonDecoderTests.java
+15
-17
spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java
...ngframework/http/codec/json/Jackson2JsonEncoderTests.java
+10
-15
spring-web/src/test/java/org/springframework/http/codec/json/JsonObjectDecoderTests.java
...ringframework/http/codec/json/JsonObjectDecoderTests.java
+5
-4
spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlDecoderTests.java
.../springframework/http/codec/xml/Jaxb2XmlDecoderTests.java
+16
-15
spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlEncoderTests.java
.../springframework/http/codec/xml/Jaxb2XmlEncoderTests.java
+7
-6
spring-web/src/test/java/org/springframework/http/codec/xml/XmlEventDecoderTests.java
.../springframework/http/codec/xml/XmlEventDecoderTests.java
+3
-2
未找到文件。
spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java
浏览文件 @
b91867cf
...
...
@@ -18,6 +18,7 @@ package org.springframework.core.codec;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
org.reactivestreams.Publisher
;
import
reactor.core.publisher.Mono
;
...
...
@@ -49,7 +50,7 @@ public abstract class AbstractDecoder<T> implements Decoder<T> {
}
@Override
public
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
public
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
if
(
mimeType
==
null
)
{
return
true
;
}
...
...
@@ -58,7 +59,7 @@ public abstract class AbstractDecoder<T> implements Decoder<T> {
@Override
public
Mono
<
T
>
decodeToMono
(
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
throw
new
UnsupportedOperationException
();
}
...
...
spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java
浏览文件 @
b91867cf
...
...
@@ -18,6 +18,7 @@ package org.springframework.core.codec;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.core.ResolvableType
;
import
org.springframework.util.MimeType
;
...
...
@@ -45,7 +46,7 @@ public abstract class AbstractEncoder<T> implements Encoder<T> {
}
@Override
public
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
public
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
if
(
mimeType
==
null
)
{
return
true
;
}
...
...
spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java
浏览文件 @
b91867cf
...
...
@@ -16,6 +16,8 @@
package
org.springframework.core.codec
;
import
java.util.Map
;
import
org.reactivestreams.Publisher
;
import
reactor.core.publisher.Flux
;
...
...
@@ -41,13 +43,13 @@ public abstract class AbstractSingleValueEncoder<T> extends AbstractEncoder<T> {
@Override
public
final
Flux
<
DataBuffer
>
encode
(
Publisher
<?
extends
T
>
inputStream
,
DataBufferFactory
bufferFactory
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
return
Flux
.
from
(
inputStream
).
take
(
1
).
concatMap
(
t
->
{
try
{
return
encode
(
t
,
bufferFactory
,
elementType
,
mimeType
);
return
encode
(
t
,
bufferFactory
,
elementType
,
mimeType
,
hints
);
}
catch
(
Exception
ex
)
{
return
Flux
.
error
(
ex
);
...
...
@@ -66,6 +68,6 @@ public abstract class AbstractSingleValueEncoder<T> extends AbstractEncoder<T> {
* @throws Exception in case of errors
*/
protected
abstract
Flux
<
DataBuffer
>
encode
(
T
t
,
DataBufferFactory
dataBufferFactory
,
ResolvableType
type
,
MimeType
mimeType
,
Object
...
hints
)
throws
Exception
;
ResolvableType
type
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
throws
Exception
;
}
spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java
浏览文件 @
b91867cf
...
...
@@ -17,6 +17,7 @@
package
org.springframework.core.codec
;
import
java.nio.ByteBuffer
;
import
java.util.Map
;
import
org.reactivestreams.Publisher
;
import
reactor.core.publisher.Flux
;
...
...
@@ -42,14 +43,14 @@ public class ByteBufferDecoder extends AbstractDecoder<ByteBuffer> {
@Override
public
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
public
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
Class
<?>
clazz
=
elementType
.
getRawClass
();
return
(
super
.
canDecode
(
elementType
,
mimeType
,
hints
)
&&
ByteBuffer
.
class
.
isAssignableFrom
(
clazz
));
}
@Override
public
Flux
<
ByteBuffer
>
decode
(
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
return
Flux
.
from
(
inputStream
).
map
((
dataBuffer
)
->
{
ByteBuffer
copy
=
ByteBuffer
.
allocate
(
dataBuffer
.
readableByteCount
());
...
...
spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java
浏览文件 @
b91867cf
...
...
@@ -17,6 +17,7 @@
package
org.springframework.core.codec
;
import
java.nio.ByteBuffer
;
import
java.util.Map
;
import
org.reactivestreams.Publisher
;
import
reactor.core.publisher.Flux
;
...
...
@@ -41,7 +42,7 @@ public class ByteBufferEncoder extends AbstractEncoder<ByteBuffer> {
@Override
public
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
public
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
Class
<?>
clazz
=
elementType
.
getRawClass
();
return
(
super
.
canEncode
(
elementType
,
mimeType
,
hints
)
&&
ByteBuffer
.
class
.
isAssignableFrom
(
clazz
));
}
...
...
@@ -49,7 +50,7 @@ public class ByteBufferEncoder extends AbstractEncoder<ByteBuffer> {
@Override
public
Flux
<
DataBuffer
>
encode
(
Publisher
<?
extends
ByteBuffer
>
inputStream
,
DataBufferFactory
bufferFactory
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
Map
<
String
,
Object
>
hints
)
{
return
Flux
.
from
(
inputStream
).
map
(
bufferFactory:
:
wrap
);
}
...
...
spring-core/src/main/java/org/springframework/core/codec/CharSequenceEncoder.java
浏览文件 @
b91867cf
...
...
@@ -20,6 +20,7 @@ import java.nio.ByteBuffer;
import
java.nio.CharBuffer
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Map
;
import
org.reactivestreams.Publisher
;
import
reactor.core.publisher.Flux
;
...
...
@@ -48,7 +49,7 @@ public class CharSequenceEncoder extends AbstractEncoder<CharSequence> {
@Override
public
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
public
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
Class
<?>
clazz
=
elementType
.
getRawClass
();
return
(
super
.
canEncode
(
elementType
,
mimeType
,
hints
)
&&
CharSequence
.
class
.
isAssignableFrom
(
clazz
));
}
...
...
@@ -56,7 +57,7 @@ public class CharSequenceEncoder extends AbstractEncoder<CharSequence> {
@Override
public
Flux
<
DataBuffer
>
encode
(
Publisher
<?
extends
CharSequence
>
inputStream
,
DataBufferFactory
bufferFactory
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
Charset
charset
;
if
(
mimeType
!=
null
&&
mimeType
.
getCharset
()
!=
null
)
{
...
...
spring-core/src/main/java/org/springframework/core/codec/Decoder.java
浏览文件 @
b91867cf
...
...
@@ -16,7 +16,9 @@
package
org.springframework.core.codec
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
org.reactivestreams.Publisher
;
import
reactor.core.publisher.Flux
;
...
...
@@ -42,10 +44,10 @@ public interface Decoder<T> {
* type of the source stream.
* @param elementType the target element type for the output stream
* @param mimeType the mime type associated with the stream to decode
* @param hints additional information about how to do
decode, optional
* @param hints additional information about how to do
encode
* @return {@code true} if supported, {@code false} otherwise
*/
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
);
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
);
/**
* Decode a {@link DataBuffer} input stream into a Flux of {@code T}.
...
...
@@ -54,11 +56,11 @@ public interface Decoder<T> {
* this type must have been previously passed to the {@link #canDecode}
* method and it must have returned {@code true}.
* @param mimeType the MIME type associated with the input stream, optional
* @param hints additional information about how to do
decode, optional
* @param hints additional information about how to do
encode
* @return the output stream with decoded elements
*/
Flux
<
T
>
decode
(
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
);
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
);
/**
* Decode a {@link DataBuffer} input stream into a Mono of {@code T}.
...
...
@@ -67,11 +69,11 @@ public interface Decoder<T> {
* this type must have been previously passed to the {@link #canDecode}
* method and it must have returned {@code true}.
* @param mimeType the MIME type associated with the input stream, optional
* @param hints additional information about how to do
decode, optional
* @param hints additional information about how to do
encode
* @return the output stream with the decoded element
*/
Mono
<
T
>
decodeToMono
(
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
);
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
);
/**
* Return the list of MIME types this decoder supports.
...
...
spring-core/src/main/java/org/springframework/core/codec/Encoder.java
浏览文件 @
b91867cf
...
...
@@ -16,7 +16,9 @@
package
org.springframework.core.codec
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
org.reactivestreams.Publisher
;
import
reactor.core.publisher.Flux
;
...
...
@@ -43,10 +45,10 @@ public interface Encoder<T> {
* type for the output stream.
* @param elementType the type of elements in the source stream
* @param mimeType the MIME type for the output stream
* @param hints additional information about how to do encode
, optional
* @param hints additional information about how to do encode
* @return {@code true} if supported, {@code false} otherwise
*/
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
);
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
);
/**
* Encode a stream of Objects of type {@code T} into a {@link DataBuffer}
...
...
@@ -59,11 +61,11 @@ public interface Encoder<T> {
* this type must have been previously passed to the {@link #canEncode}
* method and it must have returned {@code true}.
* @param mimeType the MIME type for the output stream
* @param hints additional information about how to do encode
, optional
* @param hints additional information about how to do encode
* @return the output stream
*/
Flux
<
DataBuffer
>
encode
(
Publisher
<?
extends
T
>
inputStream
,
DataBufferFactory
bufferFactory
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
);
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
);
/**
* Return the list of mime types this encoder supports.
...
...
spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java
浏览文件 @
b91867cf
...
...
@@ -17,6 +17,7 @@
package
org.springframework.core.codec
;
import
java.io.ByteArrayInputStream
;
import
java.util.Map
;
import
org.reactivestreams.Publisher
;
import
reactor.core.publisher.Flux
;
...
...
@@ -45,7 +46,7 @@ public class ResourceDecoder extends AbstractDecoder<Resource> {
@Override
public
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
public
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
Class
<?>
clazz
=
elementType
.
getRawClass
();
return
(
InputStreamResource
.
class
.
equals
(
clazz
)
||
clazz
.
isAssignableFrom
(
ByteArrayResource
.
class
))
&&
...
...
@@ -54,7 +55,7 @@ public class ResourceDecoder extends AbstractDecoder<Resource> {
@Override
public
Flux
<
Resource
>
decode
(
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
Class
<?>
clazz
=
elementType
.
getRawClass
();
...
...
spring-core/src/main/java/org/springframework/core/codec/ResourceEncoder.java
浏览文件 @
b91867cf
...
...
@@ -18,6 +18,7 @@ package org.springframework.core.codec;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Map
;
import
reactor.core.publisher.Flux
;
...
...
@@ -56,14 +57,14 @@ public class ResourceEncoder extends AbstractSingleValueEncoder<Resource> {
@Override
public
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
public
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
Class
<?>
clazz
=
elementType
.
getRawClass
();
return
(
super
.
canEncode
(
elementType
,
mimeType
,
hints
)
&&
Resource
.
class
.
isAssignableFrom
(
clazz
));
}
@Override
protected
Flux
<
DataBuffer
>
encode
(
Resource
resource
,
DataBufferFactory
dataBufferFactory
,
ResolvableType
type
,
MimeType
mimeType
,
Object
...
hints
)
throws
IOException
{
ResolvableType
type
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
throws
IOException
{
InputStream
is
=
resource
.
getInputStream
();
return
DataBufferUtils
.
read
(
is
,
dataBufferFactory
,
bufferSize
);
...
...
spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java
浏览文件 @
b91867cf
...
...
@@ -21,6 +21,7 @@ import java.nio.charset.Charset;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.function.IntPredicate
;
import
org.reactivestreams.Publisher
;
...
...
@@ -77,14 +78,14 @@ public class StringDecoder extends AbstractDecoder<String> {
@Override
public
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
public
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
return
(
super
.
canDecode
(
elementType
,
mimeType
,
hints
)
&&
String
.
class
.
equals
(
elementType
.
getRawClass
()));
}
@Override
public
Flux
<
String
>
decode
(
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
Flux
<
DataBuffer
>
inputFlux
=
Flux
.
from
(
inputStream
);
if
(
this
.
splitOnNewline
)
{
...
...
@@ -95,7 +96,7 @@ public class StringDecoder extends AbstractDecoder<String> {
@Override
public
Mono
<
String
>
decodeToMono
(
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
return
Flux
.
from
(
inputStream
)
.
reduce
(
DataBuffer:
:
write
)
...
...
spring-core/src/test/java/org/springframework/core/codec/ByteBufferDecoderTests.java
浏览文件 @
b91867cf
...
...
@@ -17,6 +17,7 @@
package
org.springframework.core.codec
;
import
java.nio.ByteBuffer
;
import
java.util.Collections
;
import
org.junit.Test
;
import
org.reactivestreams.Publisher
;
...
...
@@ -40,9 +41,12 @@ public class ByteBufferDecoderTests extends AbstractDataBufferAllocatingTestCase
@Test
public
void
canDecode
()
{
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
ByteBuffer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertFalse
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
Integer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
ByteBuffer
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
ByteBuffer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()));
assertFalse
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
Integer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
ByteBuffer
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
,
Collections
.
emptyMap
()));
}
@Test
...
...
@@ -52,7 +56,7 @@ public class ByteBufferDecoderTests extends AbstractDataBufferAllocatingTestCase
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
fooBuffer
,
barBuffer
);
Flux
<
ByteBuffer
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClassWithGenerics
(
Publisher
.
class
,
ByteBuffer
.
class
),
null
);
null
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
output
)
.
assertNoError
()
...
...
spring-core/src/test/java/org/springframework/core/codec/ByteBufferEncoderTests.java
浏览文件 @
b91867cf
...
...
@@ -18,6 +18,7 @@ package org.springframework.core.codec;
import
java.nio.ByteBuffer
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Collections
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -48,9 +49,12 @@ public class ByteBufferEncoderTests extends AbstractDataBufferAllocatingTestCase
@Test
public
void
canEncode
()
{
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
ByteBuffer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertFalse
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
Integer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
ByteBuffer
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
ByteBuffer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()));
assertFalse
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
Integer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
ByteBuffer
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
,
Collections
.
emptyMap
()));
}
@Test
...
...
@@ -62,7 +66,7 @@ public class ByteBufferEncoderTests extends AbstractDataBufferAllocatingTestCase
Flux
<
DataBuffer
>
output
=
this
.
encoder
.
encode
(
source
,
this
.
bufferFactory
,
ResolvableType
.
forClassWithGenerics
(
Publisher
.
class
,
ByteBuffer
.
class
),
null
);
null
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
output
)
.
assertValuesWith
(
b
->
{
...
...
spring-core/src/test/java/org/springframework/core/codec/CharSequenceEncoderTests.java
浏览文件 @
b91867cf
...
...
@@ -16,6 +16,8 @@
package
org.springframework.core.codec
;
import
java.util.Collections
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -46,18 +48,23 @@ public class CharSequenceEncoderTests extends AbstractDataBufferAllocatingTestCa
@Test
public
void
canWrite
()
{
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
String
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
StringBuilder
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
StringBuffer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertFalse
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
Integer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertFalse
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
String
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
String
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
StringBuilder
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
StringBuffer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()));
assertFalse
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
Integer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()));
assertFalse
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
String
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
,
Collections
.
emptyMap
()));
}
@Test
public
void
writeString
()
throws
InterruptedException
{
Flux
<
String
>
stringFlux
=
Flux
.
just
(
"foo"
);
Flux
<
DataBuffer
>
output
=
Flux
.
from
(
this
.
encoder
.
encode
(
stringFlux
,
this
.
bufferFactory
,
null
,
null
));
this
.
encoder
.
encode
(
stringFlux
,
this
.
bufferFactory
,
null
,
null
,
Collections
.
emptyMap
()
));
TestSubscriber
.
subscribe
(
output
)
.
assertNoError
()
...
...
@@ -69,7 +76,7 @@ public class CharSequenceEncoderTests extends AbstractDataBufferAllocatingTestCa
public
void
writeStringBuilder
()
throws
InterruptedException
{
Flux
<
StringBuilder
>
stringBuilderFlux
=
Flux
.
just
(
new
StringBuilder
(
"foo"
));
Flux
<
DataBuffer
>
output
=
Flux
.
from
(
this
.
encoder
.
encode
(
stringBuilderFlux
,
this
.
bufferFactory
,
null
,
null
));
this
.
encoder
.
encode
(
stringBuilderFlux
,
this
.
bufferFactory
,
null
,
null
,
Collections
.
emptyMap
()
));
TestSubscriber
.
subscribe
(
output
)
.
assertNoError
()
...
...
spring-core/src/test/java/org/springframework/core/codec/ResourceDecoderTests.java
浏览文件 @
b91867cf
...
...
@@ -17,6 +17,7 @@
package
org.springframework.core.codec
;
import
java.io.IOException
;
import
java.util.Collections
;
import
org.junit.Test
;
import
reactor.core.publisher.Flux
;
...
...
@@ -44,14 +45,14 @@ public class ResourceDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
canDecode
()
throws
Exception
{
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
InputStreamResource
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
ByteArrayResource
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
Resource
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
InputStreamResource
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
InputStreamResource
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
ByteArrayResource
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
Resource
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
InputStreamResource
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
,
Collections
.
emptyMap
()
));
}
@Test
...
...
@@ -61,7 +62,7 @@ public class ResourceDecoderTests extends AbstractDataBufferAllocatingTestCase {
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
fooBuffer
,
barBuffer
);
Flux
<
Resource
>
result
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
Resource
.
class
),
null
);
.
decode
(
source
,
ResolvableType
.
forClass
(
Resource
.
class
),
null
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
result
)
...
...
spring-core/src/test/java/org/springframework/core/codec/ResourceEncoderTests.java
浏览文件 @
b91867cf
...
...
@@ -17,6 +17,7 @@
package
org.springframework.core.codec
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Collections
;
import
org.junit.Test
;
import
reactor.core.publisher.Flux
;
...
...
@@ -42,14 +43,14 @@ public class ResourceEncoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
canEncode
()
throws
Exception
{
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
InputStreamResource
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
ByteArrayResource
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
Resource
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
InputStreamResource
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
InputStreamResource
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
ByteArrayResource
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
Resource
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
InputStreamResource
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
,
Collections
.
emptyMap
()
));
}
@Test
...
...
@@ -61,7 +62,7 @@ public class ResourceEncoderTests extends AbstractDataBufferAllocatingTestCase {
Flux
<
DataBuffer
>
output
=
this
.
encoder
.
encode
(
source
,
this
.
bufferFactory
,
ResolvableType
.
forClass
(
Resource
.
class
),
null
);
null
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
output
)
...
...
spring-core/src/test/java/org/springframework/core/codec/StringDecoderTests.java
浏览文件 @
b91867cf
...
...
@@ -16,6 +16,8 @@
package
org.springframework.core.codec
;
import
java.util.Collections
;
import
org.junit.Test
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
...
...
@@ -41,18 +43,24 @@ public class StringDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
canDecode
()
{
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
String
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
String
.
class
),
MimeTypeUtils
.
TEXT_HTML
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
String
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
));
assertFalse
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
Integer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
));
assertFalse
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
Object
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
String
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
String
.
class
),
MimeTypeUtils
.
TEXT_HTML
,
Collections
.
emptyMap
()));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
String
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
,
Collections
.
emptyMap
()));
assertFalse
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
Integer
.
class
),
MimeTypeUtils
.
TEXT_PLAIN
,
Collections
.
emptyMap
()));
assertFalse
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
Object
.
class
),
MimeTypeUtils
.
APPLICATION_JSON
,
Collections
.
emptyMap
()));
}
@Test
public
void
decode
()
throws
InterruptedException
{
this
.
decoder
=
new
StringDecoder
(
false
);
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
"foo"
),
stringBuffer
(
"bar"
),
stringBuffer
(
"baz"
));
Flux
<
String
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
String
.
class
),
null
);
Flux
<
String
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
String
.
class
),
null
,
Collections
.
emptyMap
());
TestSubscriber
.
subscribe
(
output
)
.
assertNoError
()
...
...
@@ -65,7 +73,8 @@ public class StringDecoderTests extends AbstractDataBufferAllocatingTestCase {
DataBuffer
fooBar
=
stringBuffer
(
"\nfoo\r\nbar\r"
);
DataBuffer
baz
=
stringBuffer
(
"\nbaz"
);
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
fooBar
,
baz
);
Flux
<
String
>
output
=
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
String
.
class
),
null
);
Flux
<
String
>
output
=
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
String
.
class
),
null
,
Collections
.
emptyMap
());
TestSubscriber
.
subscribe
(
output
)
.
assertNoError
()
...
...
@@ -75,7 +84,8 @@ public class StringDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
decodeEmptyFlux
()
throws
InterruptedException
{
Flux
<
DataBuffer
>
source
=
Flux
.
empty
();
Flux
<
String
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
String
.
class
),
null
);
Flux
<
String
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
String
.
class
),
null
,
Collections
.
emptyMap
());
TestSubscriber
.
subscribe
(
output
)
.
assertNoError
()
...
...
@@ -86,7 +96,8 @@ public class StringDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
decodeEmptyString
()
throws
InterruptedException
{
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
""
));
Flux
<
String
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
String
.
class
),
null
);
Flux
<
String
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
String
.
class
),
null
,
Collections
.
emptyMap
());
TestSubscriber
.
subscribe
(
output
).
assertValues
(
""
);
}
...
...
@@ -95,7 +106,8 @@ public class StringDecoderTests extends AbstractDataBufferAllocatingTestCase {
public
void
decodeToMono
()
throws
InterruptedException
{
this
.
decoder
=
new
StringDecoder
(
false
);
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
"foo"
),
stringBuffer
(
"bar"
),
stringBuffer
(
"baz"
));
Mono
<
String
>
output
=
this
.
decoder
.
decodeToMono
(
source
,
ResolvableType
.
forClass
(
String
.
class
),
null
);
Mono
<
String
>
output
=
this
.
decoder
.
decodeToMono
(
source
,
ResolvableType
.
forClass
(
String
.
class
),
null
,
Collections
.
emptyMap
());
TestSubscriber
.
subscribe
(
output
)
.
assertNoError
()
...
...
@@ -106,7 +118,8 @@ public class StringDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
decodeToMonoWithEmptyFlux
()
throws
InterruptedException
{
Flux
<
DataBuffer
>
source
=
Flux
.
empty
();
Mono
<
String
>
output
=
this
.
decoder
.
decodeToMono
(
source
,
ResolvableType
.
forClass
(
String
.
class
),
null
);
Mono
<
String
>
output
=
this
.
decoder
.
decodeToMono
(
source
,
ResolvableType
.
forClass
(
String
.
class
),
null
,
Collections
.
emptyMap
());
TestSubscriber
.
subscribe
(
output
)
.
assertNoError
()
...
...
spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/HttpMessageWriterView.java
浏览文件 @
b91867cf
...
...
@@ -16,6 +16,7 @@
package
org.springframework.web.reactive.result.view
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
...
...
@@ -123,7 +124,7 @@ public class HttpMessageWriterView implements View {
else
if
(
map
.
size
()
==
1
)
{
return
map
.
values
().
iterator
().
next
();
}
else
if
(
getMessageWriter
().
canWrite
(
ResolvableType
.
forClass
(
Map
.
class
),
null
))
{
else
if
(
getMessageWriter
().
canWrite
(
ResolvableType
.
forClass
(
Map
.
class
),
null
,
Collections
.
emptyMap
()
))
{
return
map
;
}
else
{
...
...
@@ -142,10 +143,10 @@ public class HttpMessageWriterView implements View {
protected
boolean
isEligibleAttribute
(
String
attributeName
,
Object
attributeValue
)
{
ResolvableType
type
=
ResolvableType
.
forClass
(
attributeValue
.
getClass
());
if
(
getModelKeys
().
isEmpty
())
{
return
getMessageWriter
().
canWrite
(
type
,
null
);
return
getMessageWriter
().
canWrite
(
type
,
null
,
Collections
.
emptyMap
()
);
}
if
(
getModelKeys
().
contains
(
attributeName
))
{
if
(
getMessageWriter
().
canWrite
(
type
,
null
))
{
if
(
getMessageWriter
().
canWrite
(
type
,
null
,
Collections
.
emptyMap
()
))
{
return
true
;
}
throw
new
IllegalStateException
(
...
...
@@ -163,7 +164,8 @@ public class HttpMessageWriterView implements View {
Publisher
<?
extends
T
>
stream
=
Mono
.
just
((
T
)
value
);
ResolvableType
type
=
ResolvableType
.
forClass
(
value
.
getClass
());
ServerHttpResponse
response
=
exchange
.
getResponse
();
return
((
HttpMessageWriter
<
T
>)
getMessageWriter
()).
write
(
stream
,
type
,
contentType
,
response
);
return
((
HttpMessageWriter
<
T
>)
getMessageWriter
()).
write
(
stream
,
type
,
contentType
,
response
,
Collections
.
emptyMap
());
}
}
spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java
浏览文件 @
b91867cf
...
...
@@ -19,6 +19,7 @@ package org.springframework.web.reactive.result.method.annotation;
import
java.nio.ByteBuffer
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.concurrent.CompletableFuture
;
import
javax.xml.bind.annotation.XmlElement
;
...
...
@@ -386,7 +387,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
DataBufferFactory
dataBufferFactory
=
new
DefaultDataBufferFactory
();
Jackson2JsonEncoder
encoder
=
new
Jackson2JsonEncoder
();
return
encoder
.
encode
(
Mono
.
just
(
new
Person
(
"Robert"
)),
dataBufferFactory
,
ResolvableType
.
forClass
(
Person
.
class
),
JSON
).
map
(
DataBuffer:
:
asByteBuffer
);
ResolvableType
.
forClass
(
Person
.
class
),
JSON
,
Collections
.
emptyMap
()
).
map
(
DataBuffer:
:
asByteBuffer
);
}
@GetMapping
(
"/flux"
)
...
...
spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Codec.java
浏览文件 @
b91867cf
...
...
@@ -38,6 +38,8 @@ import org.springframework.util.MimeType;
*/
public
class
AbstractJackson2Codec
{
public
static
final
String
JSON_VIEW_HINT
=
AbstractJackson2Codec
.
class
.
getName
()
+
".jsonView"
;
protected
static
final
List
<
MimeType
>
JSON_MIME_TYPES
=
Arrays
.
asList
(
new
MimeType
(
"application"
,
"json"
,
StandardCharsets
.
UTF_8
),
new
MimeType
(
"application"
,
"*+json"
,
StandardCharsets
.
UTF_8
));
...
...
spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonDecoder.java
浏览文件 @
b91867cf
...
...
@@ -18,8 +18,8 @@ package org.springframework.http.codec.json;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
com.fasterxml.jackson.annotation.JsonView
;
import
com.fasterxml.jackson.databind.JavaType
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectReader
;
...
...
@@ -62,7 +62,7 @@ public class Jackson2JsonDecoder extends AbstractJackson2Codec implements Decode
@Override
public
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
public
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
if
(
mimeType
==
null
)
{
return
true
;
}
...
...
@@ -76,7 +76,7 @@ public class Jackson2JsonDecoder extends AbstractJackson2Codec implements Decode
@Override
public
Flux
<
Object
>
decode
(
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
JsonObjectDecoder
objectDecoder
=
this
.
fluxObjectDecoder
;
return
decodeInternal
(
objectDecoder
,
inputStream
,
elementType
,
mimeType
,
hints
);
...
...
@@ -84,14 +84,14 @@ public class Jackson2JsonDecoder extends AbstractJackson2Codec implements Decode
@Override
public
Mono
<
Object
>
decodeToMono
(
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
JsonObjectDecoder
objectDecoder
=
this
.
monoObjectDecoder
;
return
decodeInternal
(
objectDecoder
,
inputStream
,
elementType
,
mimeType
,
hints
).
singleOrEmpty
();
}
private
Flux
<
Object
>
decodeInternal
(
JsonObjectDecoder
objectDecoder
,
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
[]
hints
)
{
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
Assert
.
notNull
(
inputStream
,
"'inputStream' must not be null"
);
Assert
.
notNull
(
elementType
,
"'elementType' must not be null"
);
...
...
@@ -102,14 +102,10 @@ public class Jackson2JsonDecoder extends AbstractJackson2Codec implements Decode
JavaType
javaType
=
getJavaType
(
elementType
.
getType
(),
contextClass
);
ObjectReader
reader
;
JsonView
jsonView
=
(
methodParam
!=
null
?
methodParam
.
getParameterAnnotation
(
JsonView
.
class
)
:
null
);
Class
<?>
jsonView
=
(
Class
<?>)
hints
.
get
(
AbstractJackson2Codec
.
JSON_VIEW_HINT
);
if
(
jsonView
!=
null
)
{
Class
<?>[]
classes
=
jsonView
.
value
();
if
(
classes
.
length
!=
1
)
{
throw
new
IllegalArgumentException
(
"@JsonView only supported for response body advice "
+
"with exactly 1 class argument: "
+
methodParam
);
}
reader
=
this
.
mapper
.
readerWithView
(
classes
[
0
]).
forType
(
javaType
);
reader
=
this
.
mapper
.
readerWithView
(
jsonView
).
forType
(
javaType
);
}
else
{
reader
=
this
.
mapper
.
readerFor
(
javaType
);
...
...
spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonEncoder.java
浏览文件 @
b91867cf
...
...
@@ -20,8 +20,8 @@ import java.io.IOException;
import
java.io.OutputStream
;
import
java.nio.ByteBuffer
;
import
java.util.List
;
import
java.util.Map
;
import
com.fasterxml.jackson.annotation.JsonView
;
import
com.fasterxml.jackson.databind.JavaType
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectWriter
;
...
...
@@ -30,7 +30,6 @@ import org.reactivestreams.Publisher;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.ResolvableType
;
import
org.springframework.core.codec.CodecException
;
import
org.springframework.core.codec.Encoder
;
...
...
@@ -68,7 +67,7 @@ public class Jackson2JsonEncoder extends AbstractJackson2Codec implements Encode
@Override
public
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
public
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
if
(
mimeType
==
null
)
{
return
true
;
}
...
...
@@ -82,14 +81,14 @@ public class Jackson2JsonEncoder extends AbstractJackson2Codec implements Encode
@Override
public
Flux
<
DataBuffer
>
encode
(
Publisher
<?>
inputStream
,
DataBufferFactory
bufferFactory
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
Assert
.
notNull
(
inputStream
,
"'inputStream' must not be null"
);
Assert
.
notNull
(
bufferFactory
,
"'bufferFactory' must not be null"
);
Assert
.
notNull
(
elementType
,
"'elementType' must not be null"
);
if
(
inputStream
instanceof
Mono
)
{
return
Flux
.
from
(
inputStream
).
map
(
value
->
encodeValue
(
value
,
bufferFactory
,
elementType
));
return
Flux
.
from
(
inputStream
).
map
(
value
->
encodeValue
(
value
,
bufferFactory
,
elementType
,
hints
));
}
Mono
<
DataBuffer
>
startArray
=
Mono
.
just
(
bufferFactory
.
wrap
(
START_ARRAY_BUFFER
));
...
...
@@ -98,31 +97,25 @@ public class Jackson2JsonEncoder extends AbstractJackson2Codec implements Encode
Flux
<
DataBuffer
>
array
=
Flux
.
from
(
inputStream
)
.
concatMap
(
value
->
{
DataBuffer
arraySeparator
=
bufferFactory
.
wrap
(
SEPARATOR_BUFFER
);
return
Flux
.
just
(
encodeValue
(
value
,
bufferFactory
,
elementType
),
arraySeparator
);
return
Flux
.
just
(
encodeValue
(
value
,
bufferFactory
,
elementType
,
hints
),
arraySeparator
);
});
return
Flux
.
concat
(
startArray
,
array
.
skipLast
(
1
),
endArray
);
}
private
DataBuffer
encodeValue
(
Object
value
,
DataBufferFactory
bufferFactory
,
ResolvableType
type
)
{
private
DataBuffer
encodeValue
(
Object
value
,
DataBufferFactory
bufferFactory
,
ResolvableType
type
,
Map
<
String
,
Object
>
hints
)
{
TypeFactory
typeFactory
=
this
.
mapper
.
getTypeFactory
();
JavaType
javaType
=
typeFactory
.
constructType
(
type
.
getType
());
MethodParameter
returnType
=
(
type
.
getSource
()
instanceof
MethodParameter
?
(
MethodParameter
)
type
.
getSource
()
:
null
);
if
(
type
.
isInstance
(
value
))
{
javaType
=
getJavaType
(
type
.
getType
(),
null
);
}
ObjectWriter
writer
;
JsonView
jsonView
=
(
returnType
!=
null
?
returnType
.
getMethodAnnotation
(
JsonView
.
class
)
:
null
);
Class
<?>
jsonView
=
(
Class
<?>)
hints
.
get
(
AbstractJackson2Codec
.
JSON_VIEW_HINT
);
if
(
jsonView
!=
null
)
{
Class
<?>[]
classes
=
jsonView
.
value
();
if
(
classes
.
length
!=
1
)
{
throw
new
IllegalArgumentException
(
"@JsonView only supported for response body advice "
+
"with exactly 1 class argument: "
+
returnType
);
}
writer
=
this
.
mapper
.
writerWithView
(
classes
[
0
]);
writer
=
this
.
mapper
.
writerWithView
(
jsonView
);
}
else
{
writer
=
this
.
mapper
.
writer
();
...
...
spring-web/src/main/java/org/springframework/http/codec/json/JsonObjectDecoder.java
浏览文件 @
b91867cf
...
...
@@ -19,6 +19,7 @@ package org.springframework.http.codec.json;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.function.Function
;
import
io.netty.buffer.ByteBuf
;
...
...
@@ -96,7 +97,7 @@ class JsonObjectDecoder extends AbstractDecoder<DataBuffer> {
@Override
public
Flux
<
DataBuffer
>
decode
(
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
return
Flux
.
from
(
inputStream
)
.
flatMap
(
new
Function
<
DataBuffer
,
Publisher
<?
extends
DataBuffer
>>()
{
...
...
spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java
浏览文件 @
b91867cf
...
...
@@ -18,6 +18,7 @@ package org.springframework.http.codec.xml;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.function.Function
;
import
javax.xml.XMLConstants
;
import
javax.xml.bind.JAXBElement
;
...
...
@@ -75,7 +76,7 @@ public class Jaxb2XmlDecoder extends AbstractDecoder<Object> {
@Override
public
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
public
boolean
canDecode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
if
(
super
.
canDecode
(
elementType
,
mimeType
,
hints
))
{
Class
<?>
outputClass
=
elementType
.
getRawClass
();
return
outputClass
.
isAnnotationPresent
(
XmlRootElement
.
class
)
||
...
...
@@ -88,11 +89,11 @@ public class Jaxb2XmlDecoder extends AbstractDecoder<Object> {
@Override
public
Flux
<
Object
>
decode
(
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
Class
<?>
outputClass
=
elementType
.
getRawClass
();
Flux
<
XMLEvent
>
xmlEventFlux
=
this
.
xmlEventDecoder
.
decode
(
inputStream
,
null
,
mimeType
);
this
.
xmlEventDecoder
.
decode
(
inputStream
,
null
,
mimeType
,
hints
);
QName
typeName
=
toQName
(
outputClass
);
Flux
<
List
<
XMLEvent
>>
splitEvents
=
split
(
xmlEventFlux
,
typeName
);
...
...
spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlEncoder.java
浏览文件 @
b91867cf
...
...
@@ -18,6 +18,7 @@ package org.springframework.http.codec.xml;
import
java.io.OutputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Map
;
import
javax.xml.bind.JAXBException
;
import
javax.xml.bind.Marshaller
;
import
javax.xml.bind.annotation.XmlRootElement
;
...
...
@@ -52,7 +53,7 @@ public class Jaxb2XmlEncoder extends AbstractSingleValueEncoder<Object> {
@Override
public
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
public
boolean
canEncode
(
ResolvableType
elementType
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
if
(
super
.
canEncode
(
elementType
,
mimeType
,
hints
))
{
Class
<?>
outputClass
=
elementType
.
getRawClass
();
return
(
outputClass
.
isAnnotationPresent
(
XmlRootElement
.
class
)
||
...
...
@@ -66,7 +67,7 @@ public class Jaxb2XmlEncoder extends AbstractSingleValueEncoder<Object> {
@Override
protected
Flux
<
DataBuffer
>
encode
(
Object
value
,
DataBufferFactory
dataBufferFactory
,
ResolvableType
type
,
MimeType
mimeType
,
Object
...
hints
)
{
ResolvableType
type
,
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
try
{
DataBuffer
buffer
=
dataBufferFactory
.
allocateBuffer
(
1024
);
OutputStream
outputStream
=
buffer
.
asOutputStream
();
...
...
spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java
浏览文件 @
b91867cf
...
...
@@ -19,6 +19,7 @@ package org.springframework.http.codec.xml;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.function.Function
;
import
javax.xml.stream.XMLEventReader
;
import
javax.xml.stream.XMLInputFactory
;
...
...
@@ -89,7 +90,7 @@ public class XmlEventDecoder extends AbstractDecoder<XMLEvent> {
@Override
@SuppressWarnings
(
"unchecked"
)
public
Flux
<
XMLEvent
>
decode
(
Publisher
<
DataBuffer
>
inputStream
,
ResolvableType
elementType
,
MimeType
mimeType
,
Object
...
hints
)
{
MimeType
mimeType
,
Map
<
String
,
Object
>
hints
)
{
Flux
<
DataBuffer
>
flux
=
Flux
.
from
(
inputStream
);
if
(
useAalto
&&
aaltoPresent
)
{
...
...
spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java
浏览文件 @
b91867cf
...
...
@@ -18,7 +18,9 @@ package org.springframework.http.codec.json;
import
java.lang.reflect.Method
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
com.fasterxml.jackson.annotation.JsonView
;
import
org.junit.Test
;
...
...
@@ -46,15 +48,16 @@ public class Jackson2JsonDecoderTests extends AbstractDataBufferAllocatingTestCa
public
void
canDecode
()
{
Jackson2JsonDecoder
decoder
=
new
Jackson2JsonDecoder
();
assertTrue
(
decoder
.
canDecode
(
null
,
MediaType
.
APPLICATION_JSON
));
assertFalse
(
decoder
.
canDecode
(
null
,
MediaType
.
APPLICATION_XML
));
assertTrue
(
decoder
.
canDecode
(
null
,
MediaType
.
APPLICATION_JSON
,
Collections
.
emptyMap
()
));
assertFalse
(
decoder
.
canDecode
(
null
,
MediaType
.
APPLICATION_XML
,
Collections
.
emptyMap
()
));
}
@Test
public
void
decodePojo
()
{
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
"{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"
));
ResolvableType
elementType
=
ResolvableType
.
forClass
(
Pojo
.
class
);
Flux
<
Object
>
flux
=
new
Jackson2JsonDecoder
().
decode
(
source
,
elementType
,
null
);
Flux
<
Object
>
flux
=
new
Jackson2JsonDecoder
().
decode
(
source
,
elementType
,
null
,
Collections
.
emptyMap
());
TestSubscriber
.
subscribe
(
flux
).
assertNoError
().
assertComplete
().
assertValues
(
new
Pojo
(
"foofoo"
,
"barbar"
));
...
...
@@ -67,7 +70,8 @@ public class Jackson2JsonDecoderTests extends AbstractDataBufferAllocatingTestCa
Method
method
=
getClass
().
getDeclaredMethod
(
"handle"
,
List
.
class
);
ResolvableType
elementType
=
ResolvableType
.
forMethodParameter
(
method
,
0
);
Mono
<
Object
>
mono
=
new
Jackson2JsonDecoder
().
decodeToMono
(
source
,
elementType
,
null
);
Mono
<
Object
>
mono
=
new
Jackson2JsonDecoder
().
decodeToMono
(
source
,
elementType
,
null
,
Collections
.
emptyMap
());
TestSubscriber
.
subscribe
(
mono
).
assertNoError
().
assertComplete
().
assertValues
(
Arrays
.
asList
(
new
Pojo
(
"f1"
,
"b1"
),
new
Pojo
(
"f2"
,
"b2"
)));
...
...
@@ -79,7 +83,8 @@ public class Jackson2JsonDecoderTests extends AbstractDataBufferAllocatingTestCa
"[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]"
));
ResolvableType
elementType
=
ResolvableType
.
forClass
(
Pojo
.
class
);
Flux
<
Object
>
flux
=
new
Jackson2JsonDecoder
().
decode
(
source
,
elementType
,
null
);
Flux
<
Object
>
flux
=
new
Jackson2JsonDecoder
().
decode
(
source
,
elementType
,
null
,
Collections
.
emptyMap
());
TestSubscriber
.
subscribe
(
flux
).
assertNoError
().
assertComplete
().
assertValues
(
new
Pojo
(
"f1"
,
"b1"
),
new
Pojo
(
"f2"
,
"b2"
));
...
...
@@ -89,10 +94,10 @@ public class Jackson2JsonDecoderTests extends AbstractDataBufferAllocatingTestCa
public
void
jsonView
()
throws
Exception
{
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
"{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}"
));
ResolvableType
elementType
=
ResolvableType
.
forMethodParameter
(
JacksonController
.
class
.
getMethod
(
"foo"
,
JacksonViewBean
.
class
),
0
);
ResolvableType
elementType
=
ResolvableType
.
forClass
(
JacksonViewBean
.
class
);
Map
<
String
,
Object
>
hints
=
Collections
.
singletonMap
(
Jackson2JsonDecoder
.
JSON_VIEW_HINT
,
MyJacksonView1
.
class
);
Flux
<
JacksonViewBean
>
flux
=
new
Jackson2JsonDecoder
()
.
decode
(
source
,
elementType
,
null
).
cast
(
JacksonViewBean
.
class
);
.
decode
(
source
,
elementType
,
null
,
hints
).
cast
(
JacksonViewBean
.
class
);
TestSubscriber
.
subscribe
(
flux
)
...
...
@@ -109,7 +114,8 @@ public class Jackson2JsonDecoderTests extends AbstractDataBufferAllocatingTestCa
public
void
decodeEmptyBodyToMono
()
throws
Exception
{
Flux
<
DataBuffer
>
source
=
Flux
.
empty
();
ResolvableType
elementType
=
ResolvableType
.
forClass
(
Pojo
.
class
);
Mono
<
Object
>
flux
=
new
Jackson2JsonDecoder
().
decodeToMono
(
source
,
elementType
,
null
);
Mono
<
Object
>
flux
=
new
Jackson2JsonDecoder
().
decodeToMono
(
source
,
elementType
,
null
,
Collections
.
emptyMap
());
TestSubscriber
.
subscribe
(
flux
)
.
assertNoError
()
...
...
@@ -163,12 +169,4 @@ public class Jackson2JsonDecoderTests extends AbstractDataBufferAllocatingTestCa
}
}
private
static
class
JacksonController
{
public
JacksonViewBean
foo
(
@JsonView
(
MyJacksonView1
.
class
)
JacksonViewBean
bean
)
{
return
bean
;
}
}
}
spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java
浏览文件 @
b91867cf
...
...
@@ -16,6 +16,9 @@
package
org.springframework.http.codec.json
;
import
java.util.Collections
;
import
java.util.Map
;
import
com.fasterxml.jackson.annotation.JsonTypeInfo
;
import
com.fasterxml.jackson.annotation.JsonTypeName
;
import
com.fasterxml.jackson.annotation.JsonView
;
...
...
@@ -42,8 +45,8 @@ public class Jackson2JsonEncoderTests extends AbstractDataBufferAllocatingTestCa
@Test
public
void
canEncode
()
{
assertTrue
(
this
.
encoder
.
canEncode
(
null
,
MediaType
.
APPLICATION_JSON
));
assertFalse
(
this
.
encoder
.
canEncode
(
null
,
MediaType
.
APPLICATION_XML
));
assertTrue
(
this
.
encoder
.
canEncode
(
null
,
MediaType
.
APPLICATION_JSON
,
Collections
.
emptyMap
()
));
assertFalse
(
this
.
encoder
.
canEncode
(
null
,
MediaType
.
APPLICATION_XML
,
Collections
.
emptyMap
()
));
}
@Test
...
...
@@ -54,7 +57,7 @@ public class Jackson2JsonEncoderTests extends AbstractDataBufferAllocatingTestCa
new
Pojo
(
"foofoofoo"
,
"barbarbar"
)
);
ResolvableType
type
=
ResolvableType
.
forClass
(
Pojo
.
class
);
Flux
<
DataBuffer
>
output
=
this
.
encoder
.
encode
(
source
,
this
.
bufferFactory
,
type
,
null
);
Flux
<
DataBuffer
>
output
=
this
.
encoder
.
encode
(
source
,
this
.
bufferFactory
,
type
,
null
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
output
)
.
assertComplete
()
...
...
@@ -74,7 +77,7 @@ public class Jackson2JsonEncoderTests extends AbstractDataBufferAllocatingTestCa
public
void
encodeWithType
()
{
Flux
<
ParentClass
>
source
=
Flux
.
just
(
new
Foo
(),
new
Bar
());
ResolvableType
type
=
ResolvableType
.
forClass
(
ParentClass
.
class
);
Flux
<
DataBuffer
>
output
=
this
.
encoder
.
encode
(
source
,
this
.
bufferFactory
,
type
,
null
);
Flux
<
DataBuffer
>
output
=
this
.
encoder
.
encode
(
source
,
this
.
bufferFactory
,
type
,
null
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
output
)
.
assertComplete
()
...
...
@@ -93,8 +96,9 @@ public class Jackson2JsonEncoderTests extends AbstractDataBufferAllocatingTestCa
bean
.
setWithView2
(
"with"
);
bean
.
setWithoutView
(
"without"
);
ResolvableType
type
=
ResolvableType
.
forMethodReturnType
(
JacksonController
.
class
.
getMethod
(
"foo"
));
Flux
<
DataBuffer
>
output
=
this
.
encoder
.
encode
(
Mono
.
just
(
bean
),
this
.
bufferFactory
,
type
,
null
);
ResolvableType
type
=
ResolvableType
.
forClass
(
JacksonViewBean
.
class
);
Map
<
String
,
Object
>
hints
=
Collections
.
singletonMap
(
Jackson2JsonEncoder
.
JSON_VIEW_HINT
,
MyJacksonView1
.
class
);
Flux
<
DataBuffer
>
output
=
this
.
encoder
.
encode
(
Mono
.
just
(
bean
),
this
.
bufferFactory
,
type
,
null
,
hints
);
TestSubscriber
.
subscribe
(
output
)
.
assertComplete
()
...
...
@@ -157,13 +161,4 @@ public class Jackson2JsonEncoderTests extends AbstractDataBufferAllocatingTestCa
}
}
private
static
class
JacksonController
{
@JsonView
(
MyJacksonView1
.
class
)
public
JacksonViewBean
foo
()
{
return
null
;
}
}
}
spring-web/src/test/java/org/springframework/http/codec/json/JsonObjectDecoderTests.java
浏览文件 @
b91867cf
...
...
@@ -17,6 +17,7 @@
package
org.springframework.http.codec.json
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Collections
;
import
org.junit.Test
;
import
reactor.core.publisher.Flux
;
...
...
@@ -36,7 +37,7 @@ public class JsonObjectDecoderTests extends AbstractDataBufferAllocatingTestCase
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
"{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"
));
Flux
<
String
>
output
=
decoder
.
decode
(
source
,
null
,
null
).
map
(
JsonObjectDecoderTests:
:
toString
);
decoder
.
decode
(
source
,
null
,
null
,
Collections
.
emptyMap
()
).
map
(
JsonObjectDecoderTests:
:
toString
);
TestSubscriber
.
subscribe
(
output
)
.
assertValues
(
"{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"
);
...
...
@@ -48,7 +49,7 @@ public class JsonObjectDecoderTests extends AbstractDataBufferAllocatingTestCase
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
"{\"foo\": \"foofoo\""
),
stringBuffer
(
", \"bar\": \"barbar\"}"
));
Flux
<
String
>
output
=
decoder
.
decode
(
source
,
null
,
null
).
map
(
JsonObjectDecoderTests:
:
toString
);
decoder
.
decode
(
source
,
null
,
null
,
Collections
.
emptyMap
()
).
map
(
JsonObjectDecoderTests:
:
toString
);
TestSubscriber
.
subscribe
(
output
)
.
assertValues
(
"{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"
);
...
...
@@ -60,7 +61,7 @@ public class JsonObjectDecoderTests extends AbstractDataBufferAllocatingTestCase
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
"[{\"foo\": \"foofoo\", \"bar\": \"barbar\"},{\"foo\": \"foofoofoo\", \"bar\": \"barbarbar\"}]"
));
Flux
<
String
>
output
=
decoder
.
decode
(
source
,
null
,
null
).
map
(
JsonObjectDecoderTests:
:
toString
);
decoder
.
decode
(
source
,
null
,
null
,
Collections
.
emptyMap
()
).
map
(
JsonObjectDecoderTests:
:
toString
);
TestSubscriber
.
subscribe
(
output
)
.
assertValues
(
"{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"
,
...
...
@@ -74,7 +75,7 @@ public class JsonObjectDecoderTests extends AbstractDataBufferAllocatingTestCase
Flux
.
just
(
stringBuffer
(
"[{\"foo\": \"foofoo\", \"bar\""
),
stringBuffer
(
": \"barbar\"},{\"foo\": \"foofoofoo\", \"bar\": \"barbarbar\"}]"
));
Flux
<
String
>
output
=
decoder
.
decode
(
source
,
null
,
null
).
map
(
JsonObjectDecoderTests:
:
toString
);
decoder
.
decode
(
source
,
null
,
null
,
Collections
.
emptyMap
()
).
map
(
JsonObjectDecoderTests:
:
toString
);
TestSubscriber
.
subscribe
(
output
)
.
assertValues
(
"{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"
,
...
...
spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlDecoderTests.java
浏览文件 @
b91867cf
...
...
@@ -16,6 +16,7 @@
package
org.springframework.http.codec.xml
;
import
java.util.Collections
;
import
java.util.List
;
import
javax.xml.namespace.QName
;
import
javax.xml.stream.events.XMLEvent
;
...
...
@@ -71,23 +72,23 @@ public class Jaxb2XmlDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
canDecode
()
{
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
Pojo
.
class
),
MediaType
.
APPLICATION_XML
));
MediaType
.
APPLICATION_XML
,
Collections
.
emptyMap
()
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
Pojo
.
class
),
MediaType
.
TEXT_XML
));
MediaType
.
TEXT_XML
,
Collections
.
emptyMap
()
));
assertFalse
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
Pojo
.
class
),
MediaType
.
APPLICATION_JSON
));
MediaType
.
APPLICATION_JSON
,
Collections
.
emptyMap
()
));
assertTrue
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
TypePojo
.
class
),
MediaType
.
APPLICATION_XML
));
MediaType
.
APPLICATION_XML
,
Collections
.
emptyMap
()
));
assertFalse
(
this
.
decoder
.
canDecode
(
ResolvableType
.
forClass
(
getClass
()),
MediaType
.
APPLICATION_XML
));
MediaType
.
APPLICATION_XML
,
Collections
.
emptyMap
()
));
}
@Test
public
void
splitOneBranches
()
{
Flux
<
XMLEvent
>
xmlEvents
=
this
.
xmlEventDecoder
.
decode
(
Flux
.
just
(
stringBuffer
(
POJO_ROOT
)),
null
,
null
);
.
decode
(
Flux
.
just
(
stringBuffer
(
POJO_ROOT
)),
null
,
null
,
Collections
.
emptyMap
()
);
Flux
<
List
<
XMLEvent
>>
result
=
this
.
decoder
.
split
(
xmlEvents
,
new
QName
(
"pojo"
));
TestSubscriber
...
...
@@ -112,7 +113,7 @@ public class Jaxb2XmlDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
splitMultipleBranches
()
{
Flux
<
XMLEvent
>
xmlEvents
=
this
.
xmlEventDecoder
.
decode
(
Flux
.
just
(
stringBuffer
(
POJO_CHILD
)),
null
,
null
);
.
decode
(
Flux
.
just
(
stringBuffer
(
POJO_CHILD
)),
null
,
null
,
Collections
.
emptyMap
()
);
Flux
<
List
<
XMLEvent
>>
result
=
this
.
decoder
.
split
(
xmlEvents
,
new
QName
(
"pojo"
));
TestSubscriber
...
...
@@ -160,8 +161,8 @@ public class Jaxb2XmlDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
decodeSingleXmlRootElement
()
throws
Exception
{
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
POJO_ROOT
));
Flux
<
Object
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
Pojo
.
class
),
null
);
Flux
<
Object
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
Pojo
.
class
),
null
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
output
)
...
...
@@ -173,8 +174,8 @@ public class Jaxb2XmlDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
decodeSingleXmlTypeElement
()
throws
Exception
{
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
POJO_ROOT
));
Flux
<
Object
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
TypePojo
.
class
),
null
);
Flux
<
Object
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
TypePojo
.
class
),
null
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
output
)
...
...
@@ -186,8 +187,8 @@ public class Jaxb2XmlDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
decodeMultipleXmlRootElement
()
throws
Exception
{
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
POJO_CHILD
));
Flux
<
Object
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
Pojo
.
class
),
null
);
Flux
<
Object
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
Pojo
.
class
),
null
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
output
)
...
...
@@ -199,8 +200,8 @@ public class Jaxb2XmlDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
decodeMultipleXmlTypeElement
()
throws
Exception
{
Flux
<
DataBuffer
>
source
=
Flux
.
just
(
stringBuffer
(
POJO_CHILD
));
Flux
<
Object
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
TypePojo
.
class
),
null
);
Flux
<
Object
>
output
=
this
.
decoder
.
decode
(
source
,
ResolvableType
.
forClass
(
TypePojo
.
class
),
null
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
output
)
...
...
spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlEncoderTests.java
浏览文件 @
b91867cf
...
...
@@ -17,6 +17,7 @@
package
org.springframework.http.codec.xml
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Collections
;
import
org.junit.Test
;
import
reactor.core.publisher.Flux
;
...
...
@@ -45,18 +46,18 @@ public class Jaxb2XmlEncoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public
void
canEncode
()
{
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
Pojo
.
class
),
MediaType
.
APPLICATION_XML
));
MediaType
.
APPLICATION_XML
,
Collections
.
emptyMap
()
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
Pojo
.
class
),
MediaType
.
TEXT_XML
));
MediaType
.
TEXT_XML
,
Collections
.
emptyMap
()
));
assertFalse
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
Pojo
.
class
),
MediaType
.
APPLICATION_JSON
));
MediaType
.
APPLICATION_JSON
,
Collections
.
emptyMap
()
));
assertTrue
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
Jaxb2XmlDecoderTests
.
TypePojo
.
class
),
MediaType
.
APPLICATION_XML
));
MediaType
.
APPLICATION_XML
,
Collections
.
emptyMap
()
));
assertFalse
(
this
.
encoder
.
canEncode
(
ResolvableType
.
forClass
(
getClass
()),
MediaType
.
APPLICATION_XML
));
MediaType
.
APPLICATION_XML
,
Collections
.
emptyMap
()
));
}
@Test
...
...
@@ -64,7 +65,7 @@ public class Jaxb2XmlEncoderTests extends AbstractDataBufferAllocatingTestCase {
Flux
<
Pojo
>
source
=
Flux
.
just
(
new
Pojo
(
"foofoo"
,
"barbar"
),
new
Pojo
(
"foofoofoo"
,
"barbarbar"
));
Flux
<
DataBuffer
>
output
=
this
.
encoder
.
encode
(
source
,
this
.
bufferFactory
,
ResolvableType
.
forClass
(
Pojo
.
class
),
MediaType
.
APPLICATION_XML
);
MediaType
.
APPLICATION_XML
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
output
)
.
assertValuesWith
(
dataBuffer
->
{
...
...
spring-web/src/test/java/org/springframework/http/codec/xml/XmlEventDecoderTests.java
浏览文件 @
b91867cf
...
...
@@ -16,6 +16,7 @@
package
org.springframework.http.codec.xml
;
import
java.util.Collections
;
import
javax.xml.stream.events.XMLEvent
;
import
org.junit.Test
;
...
...
@@ -44,7 +45,7 @@ public class XmlEventDecoderTests extends AbstractDataBufferAllocatingTestCase {
public
void
toXMLEventsAalto
()
{
Flux
<
XMLEvent
>
events
=
this
.
decoder
.
decode
(
Flux
.
just
(
stringBuffer
(
XML
)),
null
,
null
);
this
.
decoder
.
decode
(
Flux
.
just
(
stringBuffer
(
XML
)),
null
,
null
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
events
)
...
...
@@ -66,7 +67,7 @@ public class XmlEventDecoderTests extends AbstractDataBufferAllocatingTestCase {
decoder
.
useAalto
=
false
;
Flux
<
XMLEvent
>
events
=
this
.
decoder
.
decode
(
Flux
.
just
(
stringBuffer
(
XML
)),
null
,
null
);
this
.
decoder
.
decode
(
Flux
.
just
(
stringBuffer
(
XML
)),
null
,
null
,
Collections
.
emptyMap
()
);
TestSubscriber
.
subscribe
(
events
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录