@@ -143,8 +143,8 @@ public <T, P extends Publisher<T>> PartBuilder asyncPart(String name, P publishe
143
143
Assert .notNull (elementType , "'elementType' must not be null" );
144
144
145
145
HttpHeaders partHeaders = new HttpHeaders ();
146
- PublisherClassPartBuilder <T , P > builder =
147
- new PublisherClassPartBuilder <>(publisher , elementClass , partHeaders );
146
+ PublisherPartBuilder <T , P > builder =
147
+ new PublisherPartBuilder <>(publisher , elementClass , partHeaders );
148
148
this .parts .add (name , builder );
149
149
return builder ;
150
150
@@ -155,21 +155,21 @@ public <T, P extends Publisher<T>> PartBuilder asyncPart(String name, P publishe
155
155
* the returned {@link PartBuilder}.
156
156
* @param name the name of the part to add (may not be empty)
157
157
* @param publisher the contents of the part to add
158
- * @param elementType the type of elements contained in the publisher
158
+ * @param typeReference the type of elements contained in the publisher
159
159
* @return a builder that allows for further header customization
160
160
*/
161
161
public <T , P extends Publisher <T >> PartBuilder asyncPart (String name , P publisher ,
162
- ParameterizedTypeReference <T > elementType ) {
162
+ ParameterizedTypeReference <T > typeReference ) {
163
163
164
- Assert .notNull (elementType , "'elementType ' must not be null" );
165
- ResolvableType elementType1 = ResolvableType .forType (elementType );
164
+ Assert .notNull (typeReference , "'typeReference ' must not be null" );
165
+ ResolvableType elementType1 = ResolvableType .forType (typeReference );
166
166
Assert .hasLength (name , "'name' must not be empty" );
167
167
Assert .notNull (publisher , "'publisher' must not be null" );
168
- Assert .notNull (elementType1 , "'elementType ' must not be null" );
168
+ Assert .notNull (elementType1 , "'typeReference ' must not be null" );
169
169
170
170
HttpHeaders partHeaders = new HttpHeaders ();
171
- PublisherTypReferencePartBuilder <T , P > builder =
172
- new PublisherTypReferencePartBuilder <>(publisher , elementType , partHeaders );
171
+ PublisherPartBuilder <T , P > builder =
172
+ new PublisherPartBuilder <>(publisher , typeReference , partHeaders );
173
173
this .parts .add (name , builder );
174
174
return builder ;
175
175
}
@@ -213,43 +213,57 @@ public HttpEntity<?> build() {
213
213
}
214
214
}
215
215
216
- private static class PublisherClassPartBuilder <S , P extends Publisher <S >>
216
+ private static class PublisherPartBuilder <S , P extends Publisher <S >>
217
217
extends DefaultPartBuilder {
218
218
219
- private final Class < S > bodyType ;
219
+ private final ResolvableType resolvableType ;
220
220
221
- public PublisherClassPartBuilder (P body , Class <S > bodyType , HttpHeaders headers ) {
221
+ public PublisherPartBuilder (P body , Class <S > elementClass , HttpHeaders headers ) {
222
222
super (body , headers );
223
- this .bodyType = bodyType ;
223
+ this .resolvableType = ResolvableType .forClass (elementClass );
224
+ }
225
+
226
+ public PublisherPartBuilder (P body , ParameterizedTypeReference <S > typeReference ,
227
+ HttpHeaders headers ) {
228
+
229
+ super (body , headers );
230
+ this .resolvableType = ResolvableType .forType (typeReference );
224
231
}
225
232
226
233
@ Override
227
234
@ SuppressWarnings ("unchecked" )
228
235
public HttpEntity <?> build () {
229
- P body = (P ) this .body ;
230
- Assert .state (body != null , "'body ' must not be null" );
231
- return HttpEntity . fromPublisher ( body , this .bodyType , this .headers );
236
+ P publisher = (P ) this .body ;
237
+ Assert .state (publisher != null , "'publisher ' must not be null" );
238
+ return new PublisherEntity <>( publisher , this .resolvableType , this .headers );
232
239
}
233
240
}
234
241
235
- private static class PublisherTypReferencePartBuilder <S , P extends Publisher <S >>
236
- extends DefaultPartBuilder {
237
242
238
- private final ParameterizedTypeReference <S > bodyType ;
243
+ /**
244
+ * Specific subtype of {@link HttpEntity} for containing {@link Publisher}s as body.
245
+ * Exposes the type contained in the publisher through {@link #getResolvableType()}.
246
+ * @param <T> The type contained in the publisher
247
+ * @param <P> The publisher
248
+ */
249
+ public static final class PublisherEntity <T , P extends Publisher <T >> extends HttpEntity <P > {
239
250
240
- public PublisherTypReferencePartBuilder (P body , ParameterizedTypeReference <S > bodyType ,
241
- HttpHeaders headers ) {
251
+ private final ResolvableType resolvableType ;
242
252
243
- super (body , headers );
244
- this .bodyType = bodyType ;
253
+
254
+ PublisherEntity (P publisher , ResolvableType resolvableType ,
255
+ @ Nullable MultiValueMap <String , String > headers ) {
256
+ super (publisher , headers );
257
+ Assert .notNull (publisher , "'publisher' must not be null" );
258
+ Assert .notNull (resolvableType , "'resolvableType' must not be null" );
259
+ this .resolvableType = resolvableType ;
245
260
}
246
261
247
- @ Override
248
- @ SuppressWarnings ("unchecked" )
249
- public HttpEntity <?> build () {
250
- P body = (P ) this .body ;
251
- Assert .state (body != null , "'body' must not be null" );
252
- return HttpEntity .fromPublisher (body , this .bodyType , this .headers );
262
+ /**
263
+ * Return the resolvable type for this entry.
264
+ */
265
+ public ResolvableType getResolvableType () {
266
+ return this .resolvableType ;
253
267
}
254
268
}
255
269
0 commit comments