Am 21.02.2014 um 07:50 schrieb itli...@schrievkrom.de:

> I have a class with an instance attribute "x" and this one contains an
> integer value.
> 
> No when exporting this to json I want to write a string instead of this
> number to the json string ...
> 
> neoJsonMapping: mapper
>  mapper for: self do: [ :mapping |
>    (mapping mapInstVar: #x to: 'x') valueSchema: #AsString.
>  ].
> 
>  mapper for: #AsString customDo: [ :mapping |
>    mapping encoder: [ :anInteger | x asString ].
>    mapping decoder: [ :aString | ... ] ].
> 
> But whatever I do ... only numbers are written out ... and yes of course
> I could add additional accessors doing the conversion.

Try

        mapping 
                mapProperty: #num
                        getter:  [ :object | (object perform: #num) asString ]
                        setter: [ :object :value |  object perform: #num 
asMutator with: value asNumber ]  ]

Norbert


Reply via email to