Skip to content

Provide configuration properties for Jackson read and write features that are common to multiple formats#48870

Closed
michaldo wants to merge 3 commits intospring-projects:mainfrom
michaldo:support-bigdecimal-plain
Closed

Provide configuration properties for Jackson read and write features that are common to multiple formats#48870
michaldo wants to merge 3 commits intospring-projects:mainfrom
michaldo:support-bigdecimal-plain

Conversation

@michaldo
Copy link
Contributor

@michaldo michaldo commented Jan 16, 2026

In Spring Boot 3 write-bigdecimal-as-plain was managed by application property.

It does not work in Spring Boot 4 that way and requires custom Java @Configuration.

Configuration via application property is automatically catch by WebMvcTest. It gives a high level of trust, because vanilla WebMvcTest may verify that plain BigDecimal works.

With custom Java @Configuration, the configuration must be added to WebMvcTest. It introduces doubt it really works in production, because test looks rigged to produce the desired result.

Anyway, when working with BigDecimal it's typical IMHO to prefer plain, and it would be nice to configure it as easy as in Spring Boot 3

Goal is

spring:
  jackson:
    stream:
      write:
        write-bigdecimal-as-plain: true

In Spring Boot 3 write-bigdecimal-as-plain was managed by application property.

It does not work in Spring Boot 4 that way and requires custom Java `@Configuration`.

Configuration via application property is automatically catch by WebMvcTest.
It gives a high level of trust, because vanilla WebMvcTest may verify that plain BigDecimal works.

With custom Java `@Configuration`, the configuration must be added to WebMvcTest. It introduces doubt it really works in production, because
test looks rigged to produce the desired result.

Anyway, when working with BigDecimal it's typical IMHO to prefer plain, and it would be nice to configure it as easy as in Spring Boot 3

Goal is

spring:
  jackson:
    stream:
      write:
        write-bigdecimal-as-plain: true

Signed-off-by: michaldo <[email protected]>
@wilkinsona
Copy link
Member

wilkinsona commented Jan 17, 2026

Thanks for the PR.

While I can see that tools.jackson.core.StreamWriteFeature.WRITE_BIGDECIMAL_AS_PLAIN controls this feature, it feels like a bit of an odd one out to me when looking at the other values of StreamWriteFeature. I would expect it to be part of tools.jackson.core.json.JsonWriteFeature alongside things like WRITE_NUMBERS_AS_STRING.

I'm reluctant to add property support for low-level input and output stream-related features just to provide a property to control how big decimals are written.

@cowtowncoder, have I misunderstood WRITE_BIG_DECIMAL_AS_PLAIN or is there a possibility that an alias could be added to JsonWriteFeature allowing it to be controlled from there?

Signed-off-by: michaldo <[email protected]>
@cowtowncoder
Copy link

cowtowncoder commented Jan 18, 2026

@wilkinsona There may be slight misunderstanding of distinction b/w StreamWriteFeature and JsonWriteFeature -- latter is not at lower level but rather:

  • StreamWriteFeature is used for multiple (and often all) format backends
  • JsonWriteFeature is JSON-specific and there are similar features for other formats (XmlWriteFeature) etc

Hence WRITE_BIG_DECIMAL_AS_PLAIN is general-purpose setting not specific to JSON and therefore should not be a JsonWriteFeature.

Having said that, I think JsonWriteFeature.WRITE_NUMBERS_AS_STRINGS is in wrong place -- it should have become StreamWriteFeature. Not sure why I did not do that back when features were split (in 2.10 or so).

@wilkinsona
Copy link
Member

@cowtowncoder, I had indeed misunderstood and should have paid more attention to the class-level javadoc. Thanks for the correction.

@wilkinsona wilkinsona changed the title Support WRITE_BIGDECIMAL_AS_PLAIN Provide configuration properties for Jackson read and write features that are common to multiple formats Jan 19, 2026
Copy link
Member

@wilkinsona wilkinsona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @michaldo. I've left a few comments for your consideration.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Jan 19, 2026
Signed-off-by: michaldo <[email protected]>
@michaldo
Copy link
Contributor Author

I applied all suggestion, but after that code asymmetry is visible (or more visible)
JacksonCborProperties class is specific for Cbor
JacksonXmlProperties class is specific for Xml
JacksonProperties class is generic and nested JacksonProperties.Json is specific for Json

It would look more consistent if all protocol specific properties are separated class or all are nested class

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 19, 2026
@wilkinsona
Copy link
Member

I applied all suggestion

Thanks.

It would look more consistent if all protocol specific properties are separated class or all are nested class

The code has its current structure due to the way in which Jackson is structured.

Jackson can always read and write JSON as the JSON-specific classes like JsonReadFeature are in the jackson-core module. This allows the JSON-specific properties to be part of JacksonProperties. XML and CBOR require a separate module (jackson-dataformat-xml and jackson-dataformat-cbor respectively). This means that JacksonXmlProperties and JacksonCborProperties need to be in separate classes.

@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Jan 20, 2026
@wilkinsona wilkinsona added this to the 4.1.x milestone Jan 20, 2026
@wilkinsona wilkinsona added the for: merge-with-amendments Needs some changes when we merge label Jan 20, 2026
@wilkinsona wilkinsona self-assigned this Jan 20, 2026
@wilkinsona wilkinsona modified the milestones: 4.1.x, 4.1.0-M1 Jan 20, 2026
wilkinsona pushed a commit that referenced this pull request Jan 20, 2026
wilkinsona added a commit that referenced this pull request Jan 20, 2026
Apply the format-agnostic read and write feature properties to all
supported mappers (CBOR, JSON, and XML), not just JSON.

See gh-48870
@wilkinsona
Copy link
Member

Thanks very much, @michaldo. This is now on main and will be included in this week's 4.1.0-M1 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for: merge-with-amendments Needs some changes when we merge type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants