mirror of
				https://github.com/OpenAPITools/openapi-generator.git
				synced 2025-10-31 08:43:45 +00:00 
			
		
		
		
	[java][webclient] Register Jackson modules on ObjectMapper (#911)
* [java][webclient] register jackson modules on object mapper * Regenerate client * Removed findAndRegisterModules() call * ObjectMapper is initialized only if NOT provided by client * Remove (now) useless DateFormat inside buildWebClient signature and regenerate client
This commit is contained in:
		
							parent
							
								
									fa9bd1f567
								
							
						
					
					
						commit
						b931da2909
					
				| @ -2,6 +2,7 @@ package {{invokerPackage}}; | |||||||
| 
 | 
 | ||||||
| import com.fasterxml.jackson.databind.DeserializationFeature; | import com.fasterxml.jackson.databind.DeserializationFeature; | ||||||
| import com.fasterxml.jackson.databind.ObjectMapper; | import com.fasterxml.jackson.databind.ObjectMapper; | ||||||
|  | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||||||
| import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||||
| import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||||
| import org.springframework.core.ParameterizedTypeReference; | import org.springframework.core.ParameterizedTypeReference; | ||||||
| @ -88,16 +89,21 @@ public class ApiClient { | |||||||
| 
 | 
 | ||||||
|     public ApiClient() { |     public ApiClient() { | ||||||
|         this.dateFormat = createDefaultDateFormat(); |         this.dateFormat = createDefaultDateFormat(); | ||||||
|         this.webClient = buildWebClient(new ObjectMapper(), dateFormat); |         ObjectMapper mapper = new ObjectMapper(); | ||||||
|  |         mapper.setDateFormat(dateFormat); | ||||||
|  |         mapper.registerModule(new JavaTimeModule()); | ||||||
|  |         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||||||
|  | 
 | ||||||
|  |         this.webClient = buildWebClient(mapper); | ||||||
|         this.init(); |         this.init(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public ApiClient(ObjectMapper mapper, DateFormat format) { |     public ApiClient(ObjectMapper mapper, DateFormat format) { | ||||||
|         this(buildWebClient(mapper.copy(), format), format); |         this(buildWebClient(mapper.copy()), format); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public ApiClient(WebClient webClient, ObjectMapper mapper, DateFormat format) { |     public ApiClient(WebClient webClient, ObjectMapper mapper, DateFormat format) { | ||||||
|         this(Optional.ofNullable(webClient).orElseGet(() ->buildWebClient(mapper.copy(), format)), format); |         this(Optional.ofNullable(webClient).orElseGet(() ->buildWebClient(mapper.copy())), format); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private ApiClient(WebClient webClient, DateFormat format) { |     private ApiClient(WebClient webClient, DateFormat format) { | ||||||
| @ -126,9 +132,7 @@ public class ApiClient { | |||||||
|     * Build the RestTemplate used to make HTTP requests. |     * Build the RestTemplate used to make HTTP requests. | ||||||
|     * @return RestTemplate |     * @return RestTemplate | ||||||
|     */ |     */ | ||||||
|     public static WebClient buildWebClient(ObjectMapper mapper, DateFormat dateFormat) { |     public static WebClient buildWebClient(ObjectMapper mapper) { | ||||||
|         mapper.setDateFormat(dateFormat); |  | ||||||
|         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |  | ||||||
|         ExchangeStrategies strategies = ExchangeStrategies |         ExchangeStrategies strategies = ExchangeStrategies | ||||||
|             .builder() |             .builder() | ||||||
|             .codecs(clientDefaultCodecsConfigurer -> { |             .codecs(clientDefaultCodecsConfigurer -> { | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ package org.openapitools.client; | |||||||
| 
 | 
 | ||||||
| import com.fasterxml.jackson.databind.DeserializationFeature; | import com.fasterxml.jackson.databind.DeserializationFeature; | ||||||
| import com.fasterxml.jackson.databind.ObjectMapper; | import com.fasterxml.jackson.databind.ObjectMapper; | ||||||
|  | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||||||
| import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||||
| import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||||
| import org.springframework.core.ParameterizedTypeReference; | import org.springframework.core.ParameterizedTypeReference; | ||||||
| @ -88,16 +89,21 @@ public class ApiClient { | |||||||
| 
 | 
 | ||||||
|     public ApiClient() { |     public ApiClient() { | ||||||
|         this.dateFormat = createDefaultDateFormat(); |         this.dateFormat = createDefaultDateFormat(); | ||||||
|         this.webClient = buildWebClient(new ObjectMapper(), dateFormat); |         ObjectMapper mapper = new ObjectMapper(); | ||||||
|  |         mapper.setDateFormat(dateFormat); | ||||||
|  |         mapper.registerModule(new JavaTimeModule()); | ||||||
|  |         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||||||
|  | 
 | ||||||
|  |         this.webClient = buildWebClient(mapper); | ||||||
|         this.init(); |         this.init(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public ApiClient(ObjectMapper mapper, DateFormat format) { |     public ApiClient(ObjectMapper mapper, DateFormat format) { | ||||||
|         this(buildWebClient(mapper.copy(), format), format); |         this(buildWebClient(mapper.copy()), format); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public ApiClient(WebClient webClient, ObjectMapper mapper, DateFormat format) { |     public ApiClient(WebClient webClient, ObjectMapper mapper, DateFormat format) { | ||||||
|         this(Optional.ofNullable(webClient).orElseGet(() ->buildWebClient(mapper.copy(), format)), format); |         this(Optional.ofNullable(webClient).orElseGet(() ->buildWebClient(mapper.copy())), format); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private ApiClient(WebClient webClient, DateFormat format) { |     private ApiClient(WebClient webClient, DateFormat format) { | ||||||
| @ -127,9 +133,7 @@ public class ApiClient { | |||||||
|     * Build the RestTemplate used to make HTTP requests. |     * Build the RestTemplate used to make HTTP requests. | ||||||
|     * @return RestTemplate |     * @return RestTemplate | ||||||
|     */ |     */ | ||||||
|     public static WebClient buildWebClient(ObjectMapper mapper, DateFormat dateFormat) { |     public static WebClient buildWebClient(ObjectMapper mapper) { | ||||||
|         mapper.setDateFormat(dateFormat); |  | ||||||
|         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |  | ||||||
|         ExchangeStrategies strategies = ExchangeStrategies |         ExchangeStrategies strategies = ExchangeStrategies | ||||||
|             .builder() |             .builder() | ||||||
|             .codecs(clientDefaultCodecsConfigurer -> { |             .codecs(clientDefaultCodecsConfigurer -> { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user