We are seeking to enhance our application's resilience and development experience by introducing environment-specific behavior for JSON deserialization. Specifically, we would like the application to ignore unknown properties in JSON payloads in production environments (prod) to prevent exceptions and ensure smooth operation when consuming external APIs that may evolve. Conversely, in development (local) environments, we want to enforce strict checking, where any unknown properties in the payload would cause a deserialization exception, thus catching potential issues early during the development process.
Current Behavior
Currently, our application's deserialization configuration is static and does not differentiate between development and production environments. This setup can lead to uncaught issues making their way into production or overly strict handling of API changes in production, potentially causing unnecessary failures.
Desired Behavior
In Development (local): The application should fail with a clear exception if the JSON payload contains unknown properties. This strict checking will help us identify and fix mapping issues or discrepancies between our models and the consumed API payloads early in the development cycle.
In other environments: The application should ignore any unknown properties in JSON payloads. This flexibility will allow our application to be more resilient to minor changes in the APIs we consume, reducing the risk of unexpected downtime or failures due to non-critical API changes.
Suggested Implementation
We propose to utilize Spring Boot's profiles or a similar mechanism to dynamically configure Jackson's DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES based on the active environment. Here's a conceptual approach:
Define a configuration bean that sets the FAIL_ON_UNKNOWN_PROPERTIES feature to false as default and true for development profiles.
Ensure this configuration is applied globally to all Jackson ObjectMapper instances or selectively, based on specific use cases.
Impact
Implementing this feature will:
Improve our development workflow by catching potential integration issues earlier.
Increase our deployed environment's resilience to changes in external APIs.
Provide a flexible, easy-to-configure mechanism for handling JSON deserialization that can adapt to different environments and requirements.
Summary
We are seeking to enhance our application's resilience and development experience by introducing environment-specific behavior for JSON deserialization. Specifically, we would like the application to ignore unknown properties in JSON payloads in production environments (prod) to prevent exceptions and ensure smooth operation when consuming external APIs that may evolve. Conversely, in development (local) environments, we want to enforce strict checking, where any unknown properties in the payload would cause a deserialization exception, thus catching potential issues early during the development process. Current Behavior
Currently, our application's deserialization configuration is static and does not differentiate between development and production environments. This setup can lead to uncaught issues making their way into production or overly strict handling of API changes in production, potentially causing unnecessary failures. Desired Behavior
Suggested Implementation
We propose to utilize Spring Boot's profiles or a similar mechanism to dynamically configure Jackson's DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES based on the active environment. Here's a conceptual approach:
Impact
Implementing this feature will: