-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Update the JSON toString() to allow better debugging #4659
Conversation
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
This would be in Vert.x 5 only, right? Asking because of the breaking aspect. Is the inspection format standardized or have you inspired from what other platforms provide? |
@tsegismont yes, this is 5.0.0 only. The format is similar to what the java Map/List does with a small difference: e.g.:
This format uses V8/node uses the format the PR uses, but does escape strings, to avoid showing stuff like:
And node/python do have options for ascii coloring and choosing between compact (single line output) versus (indented output). Given that in the JDK the norm is to use a compact |
This PR is very useful for: eclipse-vertx/vertx-json-schema#100 |
When logging large objects having the output be JSON is particularly useful because we can stick it somewhere else, reformat it and read it easily. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@pmlopes as discussed off-list, it would be nice to have a switch for old behavior as we had for Base64 encoding/decoding |
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
I've added a flag |
@Yaytay this PR will not change the JSON encoding, you can still encode it with For example on a large object
Note the
BUT if you do:
You still see the full thing: {"created":"2020-05-12T15:10:37Z","device":{"device_info":{"device_fw":204,"device_sn":"06-02133","device_trait":2,"device_type":190},"timeseries":[{"configuration":{"sensors":[{"measurements":["BATTERY","BATTERY_MV"],"port":7,"sensor_bonus_value":"Unavailable","sensor_firmware_ver":"Unavailable","sensor_number":133,"sensor_sn":"Unavailable"},{"measurements":["REFERENCE_KPA","TEMPC_LOGGER"],"port":8,"sensor_bonus_value":"Unavailable","sensor_firmware_ver":"Unavailable","sensor_number":134,"sensor_sn":"Unavailable"}],"valid_since":"2018-08-11T21:45:00Z","values":[[1534023900,0,19,[{"description":"Battery Percent","error":false,"units":"%","value":100},{"description":"Battery Voltage","error":false,"units":" mV","value":7864}],[{"description":"Reference Pressure","error":false,"units":" kPa","value":100.62},{"description":"Logger Temperature","error":false,"units":" °C","value":28.34}]]]}}]}} |
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
this PR has been merged to rapidly, it broke the build of vertx-sql-client at least (https://github.com/eclipse-vertx/vertx-sql-client/actions/runs/4643518385/jobs/8218213912) and it might have breaken more. I will revert it for now. |
Motivation:
Vert.x JsonObject/JsonArray
toString()
methods call the codec encode method. While this is handy for debugging it has several drawbacks. When dealing with very large objects, a log statement or debug can incur on some performance penalty. Worse, when debugging, IDEs will try to show you a string representation of the object so it can impact your productivity.When debugging circular references, you will notice that the debugger will constantly throw
StackOverflowError
slowing your IDE to a non use state.This PR introduces a breaking change in the
toString()
methods ofJsonObject
andJsonArray
, note that this should not impact most users as JSON encoding should always be done withencode()
orencodePrettilly()
.The changes try to follow what other runtimes do. Like with V8 or Python
inspect
/dirs
, the proposedtoString()
methods will return a JSON like representation of the object/array. It will enforce a few limits:toString()
from a nested object will start counting from that node)The reason to avoid using the container directly is that, although
Map
andList
will detectself
references, they would fail to detect other circular references, leading again toStackOverflowError
.