Description
Verified by unit tests. This is very confusing.
false
is treated as true
, because the configurer for this only checks if there's ANY value present (it uses alwaysApplyingWhenNonNull
):
https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfiguration.java#L80C46-L80C71
The only way to set it to false is by removing the key completely.
In fact, many of these properties are behaving wrongly, and the only key that works as it should is serialize-nulls
, which properly accepts true and false values.
But the fact that it works is thanks to the PR #16323 from 2019, which added .whenTrue()
after the .map(...)
.
(I don't know if the fix was this exact PR or not, I only know that current GsonAutoConfiguration from spring-boot-autoconfigure-3.2.2 has the version with .whenTrue()
added to it.)
spring:
gson:
disable-html-escaping: false
Can we do the same thing (add .whenTrue()
) to all the other relevant options as well?
I couldn't quickly find more relevant issues, but I found stack overflow question where someone was also confused by this behavior.