Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several gson properties, including spring.gson.disable-html-escaping, do not behave correctly when set to false #39504

Closed
daliborfilus opened this issue Feb 10, 2024 · 0 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@daliborfilus
Copy link

daliborfilus commented Feb 10, 2024

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 10, 2024
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 12, 2024
@wilkinsona wilkinsona added this to the 3.1.x milestone Feb 12, 2024
@wilkinsona wilkinsona self-assigned this Feb 12, 2024
@wilkinsona wilkinsona modified the milestones: 3.1.x, 3.1.9 Feb 12, 2024
@wilkinsona wilkinsona changed the title Gson - Config spring.gson.disable-html-escaping: false disables html escaping Several gson properties, including spring.gson.disable-html-escaping, do not behave correctly when set to false Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants