Stef,
On 16 Dec 2016, at 15:00, stepharong <stepharong@free.fr> wrote:
Hi sven
I'm trying to adapt the teapot library example to get a simple item collector (as a project for a future book) and so that I can learn and use it for my PS2/PS3 game collection :)
Now when I set up teapot to emit JSON I get an NeoJSONMappingNotFound In the library example attila does not manipulate objects but dictionaries. So I imagine that I have to do something :) I read the NeoJSON chapter but I did not find the solution.
Should I implement neoJsonOn: on my domain?
Section 5 of https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBook/lastSuccessfu... explains most of this. You either add the mapping to the writer, builder style, or you add it to the class side of your model objects as #neoJsonMapping: (search for implementors as examples). I see that this second aspect is not well explained in the book. In the simplest case, the following is enough: neoJsonMapping: mapper mapper for: self do: [ :mapping | mapping mapInstVars: #(id width height data) ] But is gets a bit more complicated with inheritance. In a last resort you could also overwrite #neoJsonOn: Now, this is all for the writer side. Reading is harder because JSON has no type info (that what STON adds, among others), so you have to tell the reader what (static) type you want the parser to create. This is based on the same mapping. This is what #nextAs: does. If you have a more complex graph with collection values, you need to type all of them 'statically'. There are some examples in the unit tests. Sven
Stef
-- Using Opera's mail client: http://www.opera.com/mail/