[Pharo-dev] NeoJSONCustomMapping>>#mapWithValueSchema:

Stéphane Ducasse stephane.ducasse at inria.fr
Fri Aug 30 07:58:06 EDT 2013


sven can you add it to the readme so that when I turn it into a pier chapter we get it :)



> Using the newly added NeoJSONCustomMapping>>#mapWithValueSchema: this is now possible, as the following unit test shows:
> 
> testDictionaryOfObject2
>  | data json reader |
>  data := Dictionary new.
>  data 
>    at: #one put: NeoJSONTestObject2 example1;
>    at: #two put: NeoJSONTestObject2 example1.
>  json := NeoJSONWriter toString: data.
>  reader := NeoJSONReader on: json readStream.
>  reader for: #DictionaryOfObject2 customDo: [ :mapping |
>    mapping mapWithValueSchema: NeoJSONTestObject2 ].  
>  self 
>    assert: (reader nextAs: #DictionaryOfObject2)
>    equals: data
> 
> Note that the mapping mechanism in NeoJSON is optional. Without mapping you get Arrays and Dictionaries back, that you can then convert to your domain objects in the a next step. With mapping however, these intermediary representations are not used and maps or lists are parsed while creating and populating your domain objects directly, which should be more efficient. This does of course introduce the necessity of adding some form of static typing.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20130830/73af688a/attachment-0002.html>


More information about the Pharo-dev mailing list