Remove all non null values that are returned#813
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request configures Jackson JSON serialization to exclude null values from API responses and resolves conflicts with springdoc-openapi-ui by removing redundant @EnableWebMvc annotations.
- Configured Jackson ObjectMapper to omit null properties during serialization
- Removed @EnableWebMvc annotations from RestConfiguration classes
- Added WebMvcConfigurer implementations to register custom Jackson message converters
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| basyx.submodelregistry/.../WebMvcConfig.java | New configuration class to register custom Jackson message converter |
| basyx.submodelregistry/.../RestConfiguration.java | Removed @EnableWebMvc annotation to resolve springdoc conflicts |
| basyx.aasregistry/.../WebMvcConfig.java | New configuration class to register custom Jackson message converter |
| basyx.aasregistry/.../RestConfiguration.java | Removed @EnableWebMvc annotation and import to resolve springdoc conflicts |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| } | ||
|
|
||
| @Override | ||
| public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
There was a problem hiding this comment.
The implementation replaces all default message converters by adding only the custom converter. Consider using extendMessageConverters() instead to preserve default converters while adding the custom one, or clear and re-add all necessary converters explicitly.
| public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | |
| public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { |
| @Component | ||
| public class WebMvcConfig implements WebMvcConfigurer { | ||
|
|
||
| private MappingJackson2HttpMessageConverter converter; |
There was a problem hiding this comment.
The field should be declared as final since it's only assigned in the constructor and never modified afterwards.
| private MappingJackson2HttpMessageConverter converter; | |
| private final MappingJackson2HttpMessageConverter converter; |
| @Component | ||
| public class WebMvcConfig implements WebMvcConfigurer { | ||
|
|
||
| private MappingJackson2HttpMessageConverter converter; |
There was a problem hiding this comment.
The field should be declared as final since it's only assigned in the constructor and never modified afterwards.
| private MappingJackson2HttpMessageConverter converter; | |
| private final MappingJackson2HttpMessageConverter converter; |
…/java/org/eclipse/digitaltwin/basyx/submodelregistry/service/configuration/WebMvcConfig.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…02/basyx-java-server-sdk into no-null-values-from-backend
- Removed custom MappingJackson2HttpMessageConverter bean - Removed unnecessary WebMvcConfigurer - Updated ObjectMapper bean to use existing Jackson2ObjectMapperBuilder with: - NON_NULL serialization inclusion - Disabled WRITE_DATES_AS_TIMESTAMPS - Root cause: @EnableWebMvc was overriding Spring Boot defaults, breaking message converters and static resources - Now relies on Spring Boot auto-configuration for converters and static resources refs eclipse-basyx#640
Closes #630
Description:
This pull request configures the Jackson ObjectMapper to exclude null values during JSON serialization. As a result, API responses no longer include fields with null values, leading to cleaner and more efficient payloads.
Changes:
Configured Jackson2ObjectMapperBuilder to omit null properties
API responses are now free of null fields
To resolve conflicts with springdoc-openapi-ui, the redundant @EnableWebMvc annotation was removed, as Spring Boot automatically configures MVC when using spring-boot-starter-web.