@@ -214,7 +214,8 @@ public Builder mutate() {
214
214
215
215
@ SuppressWarnings ({"rawtypes" , "unchecked" })
216
216
private <T > @ Nullable T readWithMessageConverters (
217
- ClientHttpResponse clientResponse , Runnable callback , Type bodyType , Class <T > bodyClass ) {
217
+ ClientHttpResponse clientResponse , Runnable callback , Type bodyType , Class <T > bodyClass ,
218
+ @ Nullable Map <String , Object > hints ) {
218
219
219
220
MediaType contentType = getContentType (clientResponse );
220
221
@@ -241,7 +242,7 @@ else if (messageConverter instanceof SmartHttpMessageConverter smartMessageConve
241
242
if (logger .isDebugEnabled ()) {
242
243
logger .debug ("Reading to [" + resolvableType + "]" );
243
244
}
244
- return (T ) smartMessageConverter .read (resolvableType , responseWrapper , null );
245
+ return (T ) smartMessageConverter .read (resolvableType , responseWrapper , hints );
245
246
}
246
247
}
247
248
else if (messageConverter .canRead (bodyClass , contentType )) {
@@ -308,6 +309,8 @@ private class DefaultRequestBodyUriSpec implements RequestBodyUriSpec {
308
309
309
310
private @ Nullable Consumer <ClientHttpRequest > httpRequestConsumer ;
310
311
312
+ private @ Nullable Map <String , Object > hints ;
313
+
311
314
public DefaultRequestBodyUriSpec (HttpMethod httpMethod ) {
312
315
this .httpMethod = httpMethod ;
313
316
}
@@ -478,6 +481,21 @@ public RequestBodySpec body(StreamingHttpOutputMessage.Body body) {
478
481
return this ;
479
482
}
480
483
484
+ @ Override
485
+ public DefaultRequestBodyUriSpec hint (String key , Object value ) {
486
+ getHints ().put (key , value );
487
+ return this ;
488
+ }
489
+
490
+ private Map <String , Object > getHints () {
491
+ Map <String , Object > hints = this .hints ;
492
+ if (hints == null ) {
493
+ hints = new ConcurrentHashMap <>(1 );
494
+ this .hints = hints ;
495
+ }
496
+ return hints ;
497
+ }
498
+
481
499
@ SuppressWarnings ({"rawtypes" , "unchecked" })
482
500
private void writeWithMessageConverters (Object body , Type bodyType , ClientHttpRequest clientRequest )
483
501
throws IOException {
@@ -497,7 +515,7 @@ else if (messageConverter instanceof SmartHttpMessageConverter smartMessageConve
497
515
ResolvableType resolvableType = ResolvableType .forType (bodyType );
498
516
if (smartMessageConverter .canWrite (resolvableType , bodyClass , contentType )) {
499
517
logBody (body , contentType , smartMessageConverter );
500
- smartMessageConverter .write (body , resolvableType , contentType , clientRequest , null );
518
+ smartMessageConverter .write (body , resolvableType , contentType , clientRequest , this . hints );
501
519
return ;
502
520
}
503
521
}
@@ -581,7 +599,7 @@ public <T> T exchangeForRequiredValue(RequiredValueExchangeFunction<T> exchangeF
581
599
}
582
600
clientResponse = clientRequest .execute ();
583
601
observationContext .setResponse (clientResponse );
584
- ConvertibleClientHttpResponse convertibleWrapper = new DefaultConvertibleClientHttpResponse (clientResponse );
602
+ ConvertibleClientHttpResponse convertibleWrapper = new DefaultConvertibleClientHttpResponse (clientResponse , this . hints );
585
603
return exchangeFunction .exchange (clientRequest , convertibleWrapper );
586
604
}
587
605
catch (IOException ex ) {
@@ -745,6 +763,8 @@ private class DefaultResponseSpec implements ResponseSpec {
745
763
746
764
private final int defaultStatusHandlerCount ;
747
765
766
+ private @ Nullable Map <String , Object > hints ;
767
+
748
768
DefaultResponseSpec (RequestHeadersSpec <?> requestHeadersSpec ) {
749
769
this .requestHeadersSpec = requestHeadersSpec ;
750
770
this .statusHandlers .addAll (DefaultRestClient .this .defaultStatusHandlers );
@@ -777,14 +797,14 @@ private ResponseSpec onStatusInternal(StatusHandler statusHandler) {
777
797
778
798
@ Override
779
799
public <T > @ Nullable T body (Class <T > bodyType ) {
780
- return executeAndExtract ((request , response ) -> readBody (request , response , bodyType , bodyType ));
800
+ return executeAndExtract ((request , response ) -> readBody (request , response , bodyType , bodyType , this . hints ));
781
801
}
782
802
783
803
@ Override
784
804
public <T > @ Nullable T body (ParameterizedTypeReference <T > bodyType ) {
785
805
Type type = bodyType .getType ();
786
806
Class <T > bodyClass = bodyClass (type );
787
- return executeAndExtract ((request , response ) -> readBody (request , response , type , bodyClass ));
807
+ return executeAndExtract ((request , response ) -> readBody (request , response , type , bodyClass , this . hints ));
788
808
}
789
809
790
810
@ Override
@@ -801,7 +821,7 @@ public <T> ResponseEntity<T> toEntity(ParameterizedTypeReference<T> bodyType) {
801
821
802
822
private <T > ResponseEntity <T > toEntityInternal (Type bodyType , Class <T > bodyClass ) {
803
823
ResponseEntity <T > entity = executeAndExtract ((request , response ) -> {
804
- T body = readBody (request , response , bodyType , bodyClass );
824
+ T body = readBody (request , response , bodyType , bodyClass , this . hints );
805
825
try {
806
826
return ResponseEntity .status (response .getStatusCode ())
807
827
.headers (response .getHeaders ())
@@ -838,13 +858,28 @@ public ResponseEntity<Void> toBodilessEntity() {
838
858
return entity ;
839
859
}
840
860
861
+ @ Override
862
+ public ResponseSpec hint (String key , Object value ) {
863
+ getHints ().put (key , value );
864
+ return this ;
865
+ }
866
+
867
+ private Map <String , Object > getHints () {
868
+ Map <String , Object > hints = this .hints ;
869
+ if (hints == null ) {
870
+ hints = new ConcurrentHashMap <>(1 );
871
+ this .hints = hints ;
872
+ }
873
+ return hints ;
874
+ }
875
+
841
876
public <T > @ Nullable T executeAndExtract (RequestHeadersSpec .ExchangeFunction <T > exchangeFunction ) {
842
877
return this .requestHeadersSpec .exchange (exchangeFunction );
843
878
}
844
879
845
- private <T > @ Nullable T readBody (HttpRequest request , ClientHttpResponse response , Type bodyType , Class <T > bodyClass ) {
880
+ private <T > @ Nullable T readBody (HttpRequest request , ClientHttpResponse response , Type bodyType , Class <T > bodyClass , @ Nullable Map < String , Object > hints ) {
846
881
return DefaultRestClient .this .readWithMessageConverters (
847
- response , () -> applyStatusHandlers (request , response ), bodyType , bodyClass );
882
+ response , () -> applyStatusHandlers (request , response ), bodyType , bodyClass , hints );
848
883
849
884
}
850
885
@@ -871,20 +906,23 @@ private class DefaultConvertibleClientHttpResponse implements RequestHeadersSpec
871
906
872
907
private final ClientHttpResponse delegate ;
873
908
874
- public DefaultConvertibleClientHttpResponse (ClientHttpResponse delegate ) {
909
+ private final @ Nullable Map <String , Object > hints ;
910
+
911
+ public DefaultConvertibleClientHttpResponse (ClientHttpResponse delegate , @ Nullable Map <String , Object > hints ) {
875
912
this .delegate = delegate ;
913
+ this .hints = hints ;
876
914
}
877
915
878
916
@ Override
879
917
public <T > @ Nullable T bodyTo (Class <T > bodyType ) {
880
- return readWithMessageConverters (this .delegate , () -> {} , bodyType , bodyType );
918
+ return readWithMessageConverters (this .delegate , () -> {} , bodyType , bodyType , this . hints );
881
919
}
882
920
883
921
@ Override
884
922
public <T > @ Nullable T bodyTo (ParameterizedTypeReference <T > bodyType ) {
885
923
Type type = bodyType .getType ();
886
924
Class <T > bodyClass = bodyClass (type );
887
- return readWithMessageConverters (this .delegate , () -> {}, type , bodyClass );
925
+ return readWithMessageConverters (this .delegate , () -> {}, type , bodyClass , this . hints );
888
926
}
889
927
890
928
@ Override
0 commit comments