Hi,

I'm happily mapping my objects to JSON. But in order to reduce the payload
I'm looking for a way to map my objects differently depending on whether it
is the root object of the mapping or not.

Let's say I have two classes with the following instvars between
parenthesis:
* ClassA(id, name)
* ClassB(id, classA)

I'm using #neoJsonMapping: to define the mappings and (NeoJsonWriter
toString: classB) to get the JSON string.

If in the Class B mappings I reference classA (by instVar or accessor) I get
the whole ClassA instance serialized as JSON. Which is not what I want. I'd
like to have only the id of classA.

I know I can define a custom mapping using for:customDo: , but I'd like to
know if there is another way to do that.

And this relates to another point, that is how to define a schema for a
whole hierarchy of objects. All my objects are descendant of a common
superclass. 

There is no way I can do the following on different levels:
super neoJsonMapping: mapper.
mapper for: self do: [:mapping | mapping mapInstVars: #(foo) ]

Because on every call it overwrites the mapping for the schema of the
current call, ending up mapping only the instVar 'foo'.

I can work my way around this by writing more, refactoring and so on. But I
would like to know if Sven or somebody else who uses NeoJSON have some
practice patterns that would like to share with the rest of us, mere
mortals.

Best regards!


Esteban.




--
View this message in context: 
http://forum.world.st/NeoJSON-Mappings-tp4677077.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

Reply via email to