spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

HttpService Client doesn't take spring.jackson properties into account

Open mdeinum opened this issue 6 months ago • 3 comments

For an application we are building we have configured Jackson3 through some properties, notably the spring.jackson.default-property-inclusion=not_empty .

We have some HTTP Service clients in different groups and it appears as if this configuration isn't taken into account, inspecting the payload that is being send it includes null fields and empty arrays.

This is then fixed when explicitly configuring the JsonMapper for the specific group.

@Bean
public RestClientHttpServiceGroupConfigurer myGroupConfigurer(JsonMapper jsonMapper) {
    return new RestClientHttpServiceGroupConfigurer() {
        @Override
        public void configureGroups(Groups<RestClient.Builder> groups) {
            groups.filterByName("my-group")
                    .forEachClient((group, cb) ->
                            cb.configureMessageConverters(cb1 -> cb1.withJsonConverter(new JacksonJsonHttpMessageConverter(jsonMapper))));
        }
    };
}  

Am I misunderstanding the documentation, doing something wrong or is this perhaps a bug / oversight?

Versions: Spring Boot: 4.0.6 (with the default dependency versions, no overrides) Wiremock: 4.2.1

mdeinum avatar Jun 04 '26 09:06 mdeinum

Hi, I would like to help with this issue.

From what I understand, HTTP Service client groups should probably use the auto-configured Jackson JsonMapper, so settings such as spring.jackson.default-property-inclusion=not_empty are applied when serializing request bodies.

I can start by adding a focused test that reproduces the reported behavior, where null fields and empty collections are still included in the outgoing JSON payload, and then follow up with a small fix if the behavior is confirmed as a bug.

Would a contribution in that direction be welcome?

king-407 avatar Jun 04 '26 10:06 king-407

Thanks for the report, @mdeinum

I’m going to put together a minimal public repro first so the behavior is easy to verify outside of the main Spring Boot codebase. After that, I’ll work on a focused regression test and fix in Spring Boot itself.

The repro will cover spring.jackson.default-property-inclusion=not_empty with a RestClient-backed HTTP service client and will compare the expected payload with the actual serialized request body. I’ll link it here once it’s available.

jyt6640 avatar Jun 05 '26 00:06 jyt6640

I created a minimal public repro here:

https://github.com/jyt6640/spring-boot-gh-50695-repro

One correction from my earlier comment: I used spring.jackson.default-property-inclusion=non_empty in the repro. With not_empty, the application fails during property binding.

The repro currently narrows the behavior to a reactive application using a RestClient-backed HTTP service client. In that setup, the outgoing request body is:

{"name":"spring","description":null,"tags":[]}

Removing spring.main.web-application-type=reactive makes the same test pass, so I’ll use this as the basis for a focused regression test and fix.

I opened a PR with the focused regression test and fix: https://github.com/spring-projects/spring-boot/pull/50698

jyt6640 avatar Jun 05 '26 00:06 jyt6640