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

SerializerFeature.WriteBigDecimalAsPlain not working #1982

Closed
will4j opened this issue Jul 30, 2018 · 2 comments
Closed

SerializerFeature.WriteBigDecimalAsPlain not working #1982

will4j opened this issue Jul 30, 2018 · 2 comments
Labels
Milestone

Comments

@will4j
Copy link

will4j commented Jul 30, 2018

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}
@wenshao wenshao added the bug label Aug 1, 2018
@wenshao wenshao added this to the 1.2.49 milestone Aug 1, 2018
@wenshao
Copy link
Member

wenshao commented Aug 5, 2018

https://github.com/alibaba/fastjson/releases/tag/1.2.49
问题已修复,请用新版本

@wenshao wenshao closed this as completed Aug 5, 2018
@will4j
Copy link
Author

will4j commented Aug 6, 2018

nice job :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants