ralfstx / minimal-json

A fast and small JSON parser and writer for Java
MIT License
732 stars 186 forks source link

custommized format of double number's string value #117

Open beclever opened 4 years ago

beclever commented 4 years ago

I have a requirement that If the float(double) value has an exponent, the "e" MUST be in lower case. in our case,when serializing a JsonObject as a String, For example,

JsonObject jsonObj = new JsonObject();
double value=21474836471d;
jsonObj. Add (" key",value);

Because of the internal call to Json.value(value), then Double.toString(value), this becomes 2.1474836471E10

Since Json is a final class, there are no extensible way to override methods. If we provide an extension, such as my extension class Enhancejson.value method, which I can implement with Double.toString(value).toLowerCase().

My question is, if we can change Json to a non-final class, or is there a better way to solve this problem?

if no workaround, I'll consider to make a Pull Request. Thank you very much.

beclever commented 4 years ago

Since JsonNumber class's access right is the same package, even Json is a non-final class, I can't solve this problem.

sroughley commented 4 years ago

Can yu solve this by creating your own writer? PrettyPrint might show some pointers as to how:

https://github.com/ralfstx/minimal-json/blob/master/com.eclipsesource.json/src/main/java/com/eclipsesource/json/PrettyPrint.java

beclever commented 4 years ago

Since JsonWriterclass's access right is the same package, I can't extends it, then I can't create my writer extends WriteConfig, and the JsonArray.toString() or the JsonObject.toString() need the WriteConfig as parameters...

beclever commented 4 years ago

is it possible to make some key/common classes'access right to make them more extensible and configurable