Skip to content

WRITE_BIGDECIMAL_AS_PLAIN is ignored if @JsonFormat is used #2230

Closed
@pacher

Description

@pacher

I am trying to serialize BigDecimal as json string while avoiding scientific notation (kotlin):

data class Test(
    @JsonFormat(shape= JsonFormat.Shape.STRING)
    val value: BigDecimal
)

fun main() {
    val mapper = jacksonObjectMapper()
        .configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true)
    val test = Test(0.0000000005.toBigDecimal())
    println(mapper.writeValueAsString(test))
}

output {"value":"5.0E-10"}
If JsonFormat is removed, then WRITE_BIGDECIMAL_AS_PLAIN works and output is {"value":0.00000000050} (json number, not string), but trying to make it json string with JsonFormat results in WRITE_BIGDECIMAL_AS_PLAIN being ignored.

Using latest version, jackson-bom:2.9.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions