Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.8.0
-
Fix Version/s: 1.8.1, 1.9-beta-1
-
Component/s: JSON
-
Labels:None
-
Number of attachments :
Description
Currently this code:
def myObject = new MyObject() def json = new JsonBuilder(); json myObject; println JsonOutput.prettyPrint(json.toString())
Prints something like:
[
"MyObject@28db23f1"
]
My suggestion:
Introspect the object and transfer each property to json, with recursive calls for objects.
Having looked at JsonOutput.groovy and the toJson(object) method this should be easy to implement and hugely useful!
Activity
Guillaume Laforge
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Description |
Currently this code:
def myObject = new MyObject() def json = new JsonBuilder(); json myObject; println JsonOutput.prettyPrint(json.toString()) prints something like [ "MyObject@28db23f1" ] My suggestion: Introspect the object and transfer each property to json, with recursive calls for objects. Having looked at JsonOutput.groovy and the toJson(object) method this should be easy to implement and hugely useful! |
Currently this code:
{code} def myObject = new MyObject() def json = new JsonBuilder(); json myObject; println JsonOutput.prettyPrint(json.toString()) {code} Prints something like: {code} [ "MyObject@28db23f1" ] {code} My suggestion: Introspect the object and transfer each property to json, with recursive calls for objects. Having looked at JsonOutput.groovy and the toJson(object) method this should be easy to implement and hugely useful! |
Guillaume Laforge
made changes -
| Component/s | JSON [ 14751 ] |
Guillaume Laforge
made changes -
| Assignee | Guillaume Laforge [ guillaume ] |
Guillaume Laforge
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Fix Version/s | 1.8.1 [ 17223 ] | |
| Fix Version/s | 1.9-beta-1 [ 17153 ] | |
| Resolution | Fixed [ 1 ] |
Paul King
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |
When working on the JSON support, I've also thought about that marshalling/unmarshalling support.
Also in my ideas back then was the ability to customize the serialization with supporting a custom toJson() method to personalize the default output (and you could also think of other annotations to exclude certain properties, and other fancy ideas like that).
But so far, we've decided to keep things simple, and not go beyong the current support that we have now. I don't say we can't revisit that decision at all, but I'm wondering if we should go as far a what full-blown frameworks like Jackson, XStream and others do better than what we could really tackle (they are projects on their own).
So I'm curious to see if others think we should go further, or stick to something simpler. It's up for debate!