Skip to content

BigDecimalAsStringSerializer in NumberSerializer throws IllegalStateException in 2.10 #2513

@johanhaleby

Description

@johanhaleby

Hi,

I just updated from Jackson (databind) 2.9.7 to 2.10.0 as a part of updating from Spring Boot 2.1.x to 2.2. In my project I depend on jackson-dataformat-hal to generate responses to web requests. After the update to Jackson 2.10 I get the following exception when trying to serialize a field of type BigDecimal:

Caused by: java.lang.IllegalStateException: null
	at com.fasterxml.jackson.databind.ser.std.NumberSerializer$BigDecimalAsStringSerializer.valueToString(NumberSerializer.java:161)
	at com.fasterxml.jackson.databind.ser.std.NumberSerializer$BigDecimalAsStringSerializer.isEmpty(NumberSerializer.java:132)
	at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:711)
	at io.openapitools.jackson.dataformat.hal.ser.HALBeanSerializer$FilteredProperties.serialize(HALBeanSerializer.java:191)
	... 120 common frames omitted

If I have a look at com.fasterxml.jackson.databind.ser.std.NumberSerializer$BigDecimalAsStringSerializer.valueToStringit looks like this:

@Override
public String valueToString(Object value) {
    // should never be called
    throw new IllegalStateException();
}

but this method seems to be called from com.fasterxml.jackson.databind.ser.std.NumberSerializer$BigDecimalAsStringSerializer.isEmpty(NumberSerializer.java:132) just as the exception implies:

@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
    return valueToString(value).isEmpty();
}

The call to BeanPropertyWriter.serializeAsField(..) in jackson-dataformat-hal looks like this:

for (BeanPropertyWriter prop : state) {
    try {
        prop.serializeAsField(bean, jgen, provider);
    } catch (Exception e) {
        wrapAndThrow(provider, e, bean, prop.getName());
    }
}

where jgen is a JsonGenerator and provider is a SerializerProvider from Jackson 2.10.

Could this be a bug in Jackson Databind or is there something else going on?

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