Closed
Bug 625170
Opened 14 years ago
Closed 6 years ago
Enhance JSON object to serialize Java objects
Categories
(Rhino Graveyard :: Core, defect)
Tracking
(Not tracked)
RESOLVED
INACTIVE
People
(Reporter: pfnguyen, Unassigned)
Details
Attachments
(2 files)
10.58 KB,
patch
|
Details | Diff | Splinter Review | |
12.17 KB,
patch
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0b8) Gecko/20100101 Firefox/4.0b8
Build Identifier: CVS HEAD 2011-01-12
I have made a patch to support serializing Java objects from the rhino JSON object with the following features:
JavaBean objects get serialized with their getters (get* and is*) turned into property names within the JSON string (e.g. String is/getFooBar() turns into "fooBar": X) [properties that exist in Class.class and Object.class are ignored]
primitive values (I don't know rhino handles this, but I handled this case) are turned into unquoted values (except for char)
Maps are fully serialized along with all of their keys and values.
Java arrays are serialized as JSON arrays
Collections are serialized as JSON arrays
java.lang.Boolean and java.lang.Number and descendants are serialized unquoted. Everything else in java.lang.** is treated as a quotable string
cyclic structure detection (but no errors, it just omits the property in the resulting json, many java graphs are cyclic)
I haven't optimized my code to be minimal in terms of lines of code, but it should be usable and perform well as-is.
Reproducible: Always
Steps to Reproduce:
JSON.serialize(new java.io.File("/"))
Actual Results:
Currently, an exception
Expected Results:
A JSON string representing a java.io.File object
Reporter | ||
Comment 1•14 years ago
|
||
Initial feature implementation
Comment 2•14 years ago
|
||
I asked this on IRC: is it better to extend JSON or to add a method to some clearly Rhino-specific thing, that could then be passed as a filter function to JSON.stringify? Seems to me the basic JSON interface was designed for this task, doesn't need custom functionality built into it.
Reporter | ||
Updated•14 years ago
|
Attachment #503283 -
Flags: review?(igor)
Comment 3•14 years ago
|
||
Comment on attachment 503283 [details] [diff] [review]
A patch implementing support for serializing java objects
I cannot review this as I haven't work on Rhino for a few years. Use cvs log to find who landed the patches to the code in question and ask that person to review this.
Attachment #503283 -
Flags: review?(igor)
Reporter | ||
Updated•14 years ago
|
Attachment #503283 -
Flags: review?(norrisboyd)
Attachment #503283 -
Flags: review?(norrisboyd)
Reporter | ||
Comment 4•14 years ago
|
||
New patch.
Ignores static members. Serializes public fields.
Attachment #505896 -
Flags: review?
Reporter | ||
Updated•14 years ago
|
Attachment #505896 -
Flags: review? → review?(norrisboyd)
Reporter | ||
Comment 5•14 years ago
|
||
Actually, it'd be nice if NativeJSON were public as well. For my own embedded usage, I would like to call NativeJSON.serialize(context, scope, value, null, null)
Comment 6•6 years ago
|
||
Closing. Bug management is now done here:
https://github.com/mozilla/rhino
Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Resolution: --- → INACTIVE
You need to log in
before you can comment on or make changes to this bug.
Description
•