Disable Jackson FAIL_ON_INVALID_SUBTYPE in feign (#5597)

* Disable Jackson FAIL_ON_INVALID_SUBTYPE in feign

With this change, Jackson does not fail even if it doesn't recognize a
discriminator type name. This is helpful when upgrading a microservice with
a new subtype while keeping compatibility with its old clients. The instance
is returned as null instead of throwing an exception deep in the feign
framework, allowing clients to gracefully degrade.

* Disable FAIL_ON_INVALID_SUBTYPE for all Jackson-based projects
This commit is contained in:
Benjamin Douglas
2017-05-16 06:20:05 -07:00
committed by wing328
parent de427297ec
commit be3cfda3ce
12 changed files with 13 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);

View File

@@ -9,7 +9,7 @@ public class ConfigurationTest {
public void testDefaultApiClient() {
ApiClient apiClient = Configuration.getDefaultApiClient();
assertNotNull(apiClient);
assertEquals("http://petstore.swagger.io/v2", apiClient.getBasePath());
assertEquals("http://petstore.swagger.io:80/v2", apiClient.getBasePath());
assertFalse(apiClient.isDebugging());
}
}

View File

@@ -36,7 +36,7 @@ public class PetApiTest {
// the default api client is used
assertEquals(Configuration.getDefaultApiClient(), api.getApiClient());
assertNotNull(api.getApiClient());
assertEquals("http://petstore.swagger.io/v2", api.getApiClient().getBasePath());
assertEquals("http://petstore.swagger.io:80/v2", api.getApiClient().getBasePath());
assertFalse(api.getApiClient().isDebugging());
ApiClient oldClient = api.getApiClient();
@@ -54,7 +54,7 @@ public class PetApiTest {
// set api client via setter method
api.setApiClient(oldClient);
assertNotNull(api.getApiClient());
assertEquals("http://petstore.swagger.io/v2", api.getApiClient().getBasePath());
assertEquals("http://petstore.swagger.io:80/v2", api.getApiClient().getBasePath());
assertFalse(api.getApiClient().isDebugging());
}