Hi Marten, There is indeed something currently not completely implemented: #valueSchema: and #nextAs: were added afterwards for reading (for example a collection of Points), the use of this concept for writing is simply not there. (compare NeoJSONPropertyMapping>>#readObject:from: to NeoJSONPropertyMapping>>#writeObject:on:) I will think about this a bit first. On the other hand, I am not so sure your solution is good, because you cannot write a generic #AsString for reading (going from String to ?). So I would suggest one of the other solutions mentioned in this thread. Thanks for the feedback. Sven On 21 Feb 2014, at 13:56, itlists@schrievkrom.de wrote:
Hmm, I think that something is definitly missing here.
The same code but instead of using #AsString I use DateAndTime and it works as expected - and that's what I would expect: use for that property mapping a valueSchema named "AsString".
It seems to work for all classes, when there is no predefined encoding available in the running system:Integer has a mathod, DateAndTime not.
Is there any reason why is works that way ?
Marten
Am 21.02.2014 12:07, schrieb Sven Van Caekenberghe:
On 21 Feb 2014, at 09:18, Norbert Hartl <norbert@hartl.name> wrote:
Am 21.02.2014 um 07:50 schrieb itlists@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.
-- Marten Feldtmann