Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custommized format of double number's string value #117

Open
beclever opened this issue Jun 18, 2020 · 4 comments
Open

custommized format of double number's string value #117

beclever opened this issue Jun 18, 2020 · 4 comments

Comments

@beclever
Copy link

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
Copy link
Author

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

@beclever beclever changed the title custommized double number's string value custommized format of double number's string value Jun 18, 2020
@sroughley
Copy link

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

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

@beclever
Copy link
Author

beclever commented Jun 18, 2020

Since JsonWriter class'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
Copy link
Author

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

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

No branches or pull requests

2 participants