Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

SerializerFeature.WriteBigDecimalAsPlain not working #1982

@will4j

Description

@will4j

The problem dose exist or am I using the wrong way?

fastJson version: 1.2.29
java version: 1.8.0_172

    /**
     * @since 1.2.16
     */
    WriteBigDecimalAsPlain,
public class BigDecimalBean {
    private String type;
    private BigDecimal value;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public BigDecimal getValue() {
        return value;
    }

    public void setValue(BigDecimal value) {
        this.value = value;
    }

    public static void main(String[] args) throws JsonProcessingException {
        BigDecimalBean bean = new BigDecimalBean();
        bean.setType("bigDecimal");
        bean.setValue(new BigDecimal("0.0000000001"));
        ObjectMapper objectMapper = new ObjectMapper();
        System.out.println(objectMapper.writeValueAsString(bean));
        objectMapper.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true);
        System.out.println(objectMapper.writeValueAsString(bean));
        System.out.println(JSON.toJSONString(bean));
        System.out.println(JSON.toJSONString(bean, SerializerFeature.WriteBigDecimalAsPlain));
    }
}

output:

{"type":"bigDecimal","value":1E-10}
{"type":"bigDecimal","value":0.0000000001}
{"type":"bigDecimal","value":1E-10}
{"type":"bigDecimal","value":1E-10}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions