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

Generating JSON is difficult #449

Closed
GoogleCodeExporter opened this issue Mar 25, 2015 · 8 comments
Closed

Generating JSON is difficult #449

GoogleCodeExporter opened this issue Mar 25, 2015 · 8 comments

Comments

@GoogleCodeExporter
Copy link

There is #javascriptOn: that generates Javascript code, but not valid JSON. 
There needs to be some 
special method for this, like #jsonOn: that has a decent default implementation 
for arbitrary 
objects.

Original issue reported on code.google.com by renggli on 3 Sep 2009 at 12:16

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

#jsonOn: has been implemented in the latest builds, but there is no default 
implementation for arbitrary objects. 
How about this for an default implementation:

Object>>jsonOn: aStream
    | attributes |
    attributes := Dictionary new.
    self class instVarNames do:
        [ :ivarName | 
        attributes 
            at: ivarName
            put: (self instVarNamed: ivarName) ].
    aStream json: attributes

See also: http://lists.squeakfoundation.org/pipermail/seaside/2010-
February/022484.html

Original comment by Nick.A...@gmail.com on 1 Feb 2010 at 10:34

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

I don't think that Seaside should provide an implementation for arbitrary 
objects:

- Every Javascript library requires objects to be represented in JSON 
differently. To avoid giving the illusion that 
there is only one possible representation I suggest to implement jsonOn: only 
on Dictionary, 
SequenceableCollection and the various literal types.

- #instVarNames and #instVarNamed: are platform specific methods.These method 
sends would need to go to a 
platform layer.

Original comment by renggli on 2 Feb 2010 at 7:12

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

FYI, #instVarNamed: is on my list for addition to the latest Grease so it will 
be ok
shortly. #instVarNames was not planned so far.

I agree with your argument about arbitrary objects, though we do have to balance
"right" with "convenient". It does seem like the above encoding would only
*occasionally* be what you wanted... but I haven't done much JSON yet, so I may 
not
be the right one to speak to that. :)

Original comment by jfitz...@gmail.com on 2 Feb 2010 at 7:27

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

I think there is a major refactoring needed here. The code is so ugly.

I think if we move these class-side encoder methods to the instance-side (why 
the heck are they on the class-
side anyway?) we sort of have a visitor that can be easily extended and changed 
in subclasses.

Original comment by renggli on 2 Feb 2010 at 7:35

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

I guess my assumption is they were on the class-side so that they can be called 
with any Stream class. It looks 
like the JSStream is only needed if you want a String as the output (though why 
you can't just use a WriteStream 
on a string in that case, I have no idea).

Original comment by jfitz...@gmail.com on 2 Feb 2010 at 8:01

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Name: Javascript-Tests-Core-lr.49
Author: lr
Time: 2 February 2010, 10:55:20 pm
UUID: 8b845c12-6879-4e8c-b4cb-8f9fdece1fc9
Ancestors: Javascript-Tests-Core-BartGauquie.48

- merged changes of Bart Gauquie
- made JSJsonStream independent of JSStream, because that inheritance was 
rather inconvenient (delegate 
instead)

Name: Javascript-Pharo-Core-lr.5
Author: lr
Time: 2 February 2010, 10:49:23 pm
UUID: e4bc2c1d-0f22-4821-a25a-64e639994d79
Ancestors: Javascript-Pharo-Core-BartGauquie.4

- merged changes of Bart Gauquie
- made JSJsonStream independent of JSStream, because that inheritance was 
rather inconvenient (delegate 
instead)

Name: Javascript-Core-lr.76
Author: lr
Time: 2 February 2010, 10:48:43 pm
UUID: 30299522-954f-4101-b9b3-052d8db87152
Ancestors: Javascript-Core-BartGauquie.75

- merged changes of Bart Gauquie
- made JSJsonStream independent of JSStream, because that inheritance was 
rather inconvenient (delegate 
instead)

Original comment by renggli on 2 Feb 2010 at 9:56

  • Changed state: Fixed
  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Issue 543 has been merged into this issue.

Original comment by renggli on 2 Feb 2010 at 9:58

  • Added labels: ****
  • Removed labels: ****

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

No branches or pull requests

1 participant