--- Begin Message ---
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, [email protected] wrote:
> Send Pharo-users mailing list submissions to
>       [email protected]
>
> 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
>       [email protected]
>
> You can reach the person managing the list at
>       [email protected]
>
> 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 <[email protected]>
> To: [email protected]
> Subject: Re: [Pharo-users] NeoJSON with Rest
> Message-ID: <[email protected]>
> 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 <[email protected]>
> To: Sven Van Caekenberghe <[email protected]>,     Any question about pharo is
>       welcome <[email protected]>
> Subject: Re: [Pharo-users] NeoJSON with Rest
> Message-ID: <[email protected]>
> 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/lastSuccessfulBuild/artifact/book-result/NeoJSON/NeoJSON.html
>>  ?
>>
>> 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 
>>> <[email protected]> wrote:
>>>
>>>
>>> From: Asbath Sama biyalou <[email protected]>
>>> Subject: NeoJSON with Rest
>>> Date: 19 November 2016 at 08:24:13 GMT+1
>>> To: Pharo users users <[email protected]>
>>>
>>>
>>> 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.
>>>
>>>
>>>
>>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: 
> <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20161119/1367c708/attachment-0001.html>
>
> ------------------------------
>
> Message: 3
> Date: Sat, 19 Nov 2016 15:49:28 +0100
> From: Sven Van Caekenberghe <[email protected]>
> To: Asbath Sama biyalou <[email protected]>
> Cc: Any question about pharo is welcome <[email protected]>
> Subject: Re: [Pharo-users] NeoJSON with Rest
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=us-ascii
>
> This works for me:
>
> String streamContents: [ :out |
>   (NeoJSONWriter on: out)
>      for: Date customDo: [ :mapping | mapping encoder: [ :value | value 
> asDateAndTime printString ] ]; 
>      nextPut: { #date -> Date today } asDictionary ].
>       
> "'{""date"":""2016-11-19T00:00:00+01:00""}'"
>       
> String streamContents: [ :out |
>   (NeoJSONWriter on: out)
>      for: Date customDo: [ :mapping | mapping encoder: [ :value | value 
> yyyymmdd ] ]; 
>      nextPut: { #date -> Date today } asDictionary ].
>       
> "'{""date"":""2016-11-19""}'"
>
>> On 19 Nov 2016, at 15:32, Asbath Sama biyalou <[email protected]> wrote:
>>
>> 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/lastSuccessfulBuild/artifact/book-result/NeoJSON/NeoJSON.html
>>>  ?
>>>
>>> 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 
>>>> <[email protected]>
>>>>  wrote:
>>>>
>>>>
>>>> From: Asbath Sama biyalou 
>>>> <[email protected]>
>>>>
>>>> Subject: NeoJSON with Rest
>>>> Date: 19 November 2016 at 08:24:13 GMT+1
>>>> To: Pharo users users 
>>>> <[email protected]>
>>>>
>>>>
>>>>
>>>> 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.
>>>>
>>>>
>>>>
>>>>
>>>>
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Pharo-users mailing list
> [email protected]
> http://lists.pharo.org/mailman/listinfo/pharo-users_lists.pharo.org
>
>
> ------------------------------
>
> End of Pharo-users Digest, Vol 43, Issue 109
> ********************************************



--- End Message ---

Reply via email to