Skip to content

JSON.Encoder shouldn't encode a decimal as a string #219

@azizk

Description

@azizk

Hi!

I would like to raise a concern regarding the recent change that encodes Decimal.new("1.2") as "1.2" instead of 1.2.
This behaviour stems from the Jason library but in my opinion it is completely incorrect, and now this has been carried over to the Decimal library here.

This way of encoding decimals affects how data is sent to clients and other servers but also how data is dumped to the database (if ecto is configured as such).
It will break API protocols, database queries, data processing etc. when floats aren't encoded correctly preserving their natural type.

If for any reason it is desirable to encode a decimal as a string, that should be done manually by transforming the data before it is encoded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions