diff --git a/config/clients/java/template/libraries/native/JSON.mustache b/config/clients/java/template/libraries/native/JSON.mustache index a13bf2fd..9872fbb4 100644 --- a/config/clients/java/template/libraries/native/JSON.mustache +++ b/config/clients/java/template/libraries/native/JSON.mustache @@ -2,6 +2,7 @@ package {{invokerPackage}}; import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.json.JsonMapper; {{#openApiNullable}} import org.openapitools.jackson.nullable.JsonNullableModule; {{/openApiNullable}} @@ -24,11 +25,12 @@ public class JSON { private ObjectMapper mapper; public JSON() { - mapper = new ObjectMapper(); + mapper = JsonMapper.builder() + .configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true) + .configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, true) + .build(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true); - mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, true); mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);