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.

Reply via email to