Thanks kmo. It works. But I have to modify my response content type in order to make it work fine. When I take WAMimeType It doesn't work. On 19/11/2016 18:00, pharo-users-request@lists.pharo.org wrote:
Send Pharo-users mailing list submissions to pharo-users@lists.pharo.org
To subscribe or unsubscribe via the World Wide Web, visit http://lists.pharo.org/mailman/listinfo/pharo-users_lists.pharo.org or, via email, send a message with subject or body 'help' to pharo-users-request@lists.pharo.org
You can reach the person managing the list at pharo-users-owner@lists.pharo.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Pharo-users digest..."
Today's Topics:
1. Re: NeoJSON with Rest (kmo) 2. Re: NeoJSON with Rest (Asbath Sama biyalou) 3. Re: NeoJSON with Rest (Sven Van Caekenberghe)
----------------------------------------------------------------------
Message: 1 Date: Sat, 19 Nov 2016 01:36:54 -0800 (PST) From: kmo <voxkmp@gmail.com> To: pharo-users@lists.pharo.org Subject: Re: [Pharo-users] NeoJSON with Rest Message-ID: <1479548214757-4923762.post@n4.nabble.com> Content-Type: text/plain; charset=us-ascii
This works for me:
Say you have a class called MyObject and you want a JSON representation of it.
On the *class *side of MyObject add this method:
neoJsonMapping: mapper "For inheritance mapping to work, the schema/classname must be self, but the instance variables have to be enumerated manually per class"
mapper for: self do: [ :mapping | mapping mapAllInstVars ].
On the* instance *side of MyObject add:
asJson ^NeoJSONWriter toString: self.
Now you can return JSON for any instance of MyObject with a simple:
myobjectinstance asJson.
This code gives you all the instance variables of MyObject as a JSON string, but you can change the mapping statement to tailor it to include exactly what you want.
Hope this helps.
-- View this message in context: http://forum.world.st/NeoJSON-with-Rest-tp4923754p4923762.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
------------------------------
Message: 2 Date: Sat, 19 Nov 2016 15:32:36 +0100 From: Asbath Sama biyalou <asamabiyalou@yahoo.com> To: Sven Van Caekenberghe <sven@stfx.eu>, Any question about pharo is welcome <pharo-users@lists.pharo.org> Subject: Re: [Pharo-users] NeoJSON with Rest Message-ID: <9a86fe55-2dae-9a59-35b1-495b9b732072@yahoo.com> Content-Type: text/plain; charset="windows-1252"
Thank you Sven. I check those example. very helpfull.
But I use this method toJson to convert the stream to json and I get :
PrimitiveFailed: primitive #basicNew: in ByteString class failed
toJson ^ String streamContents: [ :stream | (NeoJSONWriter on: stream) for: Date customDo: [ :mapping | mapping encoder: [ :value | value asDateAndTime printString ] ]; nextPut: data ]
Did you see some errors.
On 19/11/2016 09:52, Sven Van Caekenberghe wrote:
Did you read https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBook/lastSuccessfu... ?
Did you check out the unit tests ? Some of them serve as examples. Checkout NeoJSONTestObject1 2 3 and the tests #testObject1 2 3 for example.
On 19 Nov 2016, at 08:24, Asbath Sama biyalou via Pharo-users <pharo-users@lists.pharo.org> wrote:
From: Asbath Sama biyalou <asamabiyalou@yahoo.com> Subject: NeoJSON with Rest Date: 19 November 2016 at 08:24:13 GMT+1 To: Pharo users users <pharo-users@lists.pharo.org>
Hello.
I want an example of implementation of neojson on a pharo object.
I am trying to implement neoJsonOn: method on a pharo object but when I test I get a Character mapping not found
in NeoJSONWriter.
Thanks.