[Pharo-users] NeoJSON and inheritance

phil at highoctane.be phil at highoctane.be
Mon Mar 17 12:40:29 EDT 2014


The "super" thing doesn't work.

I have spent a while tracing what was occuring with the custom mappings.

If in a subclass I do:

neoJsonMapping: aMapper
super neoJsonMapping: aMapper.
 aMapper for: self do: [ :mapping |
 mapping
mapProperty: 'startDate' getter: [ :filter | filter startDate ] setter: [
:filter :value | filter startDate: value ];
 mapProperty: 'endDate' getter: [ :filter | filter endDate ] setter: [
:filter :value | filter endDate: value ].
 ]

and in the superclass:

neoJsonMapping: aMapper
aMapper for: self do: [ :mapping |
 mapping mapInstVar: #id to: 'id'.
]

(do not pay attention to mapInstVar or mapProperty, I was figuring out how
things worked).

Thing is that the mapping goes fine up to one point.

super neoJsonMapping: aMapper

indeed puts the right 'id' mapping but then

aMapper for:: self do: [ ...

does

for: smalltalkClass do: block
"Create and add a new standard object mapping for smalltalkClass.
 The code in block should further customize the mapping."
 | mapping |
 mapping := self newObjectMappingFor: smalltalkClass.
block value: mapping.
^ mapping


which in turn:

newObjectMappingFor: smalltalkClass
| mapping |
mapping := NeoJSONObjectMapping new.
 mapping subjectClass: smalltalkClass.
self mappings at: smalltalkClass put: mapping.
^ mapping



Argh:  self mappings at: smalltalkClass put: mapping.

Overwrites the existing contents.

So, only the entries of the subclass are left.

I guess that's a bug.

I'd do:

newObjectMappingFor: smalltalkClass
 | mapping |

mapping := self mappings at: smalltalkClass.

mapping ifNil: [
 mapping := NeoJSONObjectMapping new.
mapping subjectClass: smalltalkClass.
self mappings at: smalltalkClass put: mapping.
 ].

^ mapping

instead.

Does this look right?

mapping := self newObjectMappingFor: smalltalkClass.

isn't then really intention revealing. Shouldn't we rename that to
objectMappingFor: smalltalkClass


Phil






On Fri, Sep 27, 2013 at 7:07 PM, Sven Van Caekenberghe <sven at stfx.eu> wrote:

> Norbert,
>
> On 26 Sep 2013, at 11:32, Norbert Hartl <norbert at hartl.name> wrote:
>
> > How is inheritance supposed to work in NeoJSON? I only figured it out by
> doing that manually:
> >
> > neoJsonMapping: aMapper
> >       super neoJsonMapping: aMapper.
> >       (aMapper mappingFor: self)
> >                       mapInstVar: #longitude;
> >                       mapInstVar: #latitude.
> >
> > Is there a better way to do?
> >
> > Norbert
>
> What you figured out yourself is the only inheritance that is available.
>
> The thing is, schema names (which can be plain Symbols or Class objects)
> are meant to be used for things like #ArrayOfPoints,
> #DictionaryWithUserValues which tell something about subtypes. I hurts to
> think of an inheritance for that ;-)
>
> Sven
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20140317/6e1026ac/attachment.html>


More information about the Pharo-users mailing list