1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
56
56
*/
57
57
public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport implements HttpMessageDecoder <Object > {
58
58
59
+ /**
60
+ * Until https://github.com/FasterXML/jackson-core/issues/476 is resolved,
61
+ * we need to ensure buffer recycling is off.
62
+ */
63
+ private final JsonFactory jsonFactory ;
64
+
65
+
59
66
/**
60
67
* Constructor with a Jackson {@link ObjectMapper} to use.
61
68
*/
62
69
protected AbstractJackson2Decoder (ObjectMapper mapper , MimeType ... mimeTypes ) {
63
70
super (mapper , mimeTypes );
71
+ this .jsonFactory = mapper .getFactory ().copy ()
72
+ .disable (JsonFactory .Feature .USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING );
64
73
}
65
74
66
75
@@ -76,24 +85,18 @@ public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType
76
85
public Flux <Object > decode (Publisher <DataBuffer > input , ResolvableType elementType ,
77
86
@ Nullable MimeType mimeType , @ Nullable Map <String , Object > hints ) {
78
87
79
- Flux <TokenBuffer > tokens = tokenize (input , true );
88
+ Flux <TokenBuffer > tokens = Jackson2Tokenizer . tokenize (Flux . from ( input ), this . jsonFactory , true );
80
89
return decodeInternal (tokens , elementType , mimeType , hints );
81
90
}
82
91
83
92
@ Override
84
93
public Mono <Object > decodeToMono (Publisher <DataBuffer > input , ResolvableType elementType ,
85
94
@ Nullable MimeType mimeType , @ Nullable Map <String , Object > hints ) {
86
95
87
- Flux <TokenBuffer > tokens = tokenize (input , false );
96
+ Flux <TokenBuffer > tokens = Jackson2Tokenizer . tokenize (Flux . from ( input ), this . jsonFactory , false );
88
97
return decodeInternal (tokens , elementType , mimeType , hints ).singleOrEmpty ();
89
98
}
90
99
91
- private Flux <TokenBuffer > tokenize (Publisher <DataBuffer > input , boolean tokenizeArrayElements ) {
92
- Flux <DataBuffer > inputFlux = Flux .from (input );
93
- JsonFactory factory = getObjectMapper ().getFactory ();
94
- return Jackson2Tokenizer .tokenize (inputFlux , factory , tokenizeArrayElements );
95
- }
96
-
97
100
private Flux <Object > decodeInternal (Flux <TokenBuffer > tokens , ResolvableType elementType ,
98
101
@ Nullable MimeType mimeType , @ Nullable Map <String , Object > hints ) {
99
102
0 commit comments