Hi, 

I have just found the answer for the reader:

-=-=-=-
rectangleJson := '{
  "origin" : null,
  "corner" : null
}'.

(NeoJSONReader on: rectangleJson readStream)
  mapInstVarsFor: Point;
  for: Point do: [ :mapping | 
        mapping allowNil ];
  for: Rectangle do: [ :mapping | 
     (mapping mapInstVar: #origin) valueSchema: Point.
     (mapping mapInstVar: #corner) valueSchema: Point ];
  nextAs: Rectangle.
-=-=-=-

I have an impression that there is a bug in the writer. While the following 
example works: 

-=-=-=-
String streamContents: [ :stream |
   (NeoJSONWriter on: stream)
                for: Point do: [ :mapping | 
                        mapping mapAllInstVars.
                        mapping allowNil ];
           for: Rectangle do: [ :mapping | 
                        (mapping mapInstVar: #origin) valueSchema: Point.
                        (mapping mapInstVar: #corner) valueSchema: Point ];
      nextPut: Rectangle new ].
-=-=-=-

the following example does not work: 

-=-=-=-
String streamContents: [ :stream |
   (NeoJSONWriter on: stream)
                for: Point do: [ :mapping | 
                        mapping mapAllInstVars.
                        mapping allowNil ];
           for: Rectangle do: [ :mapping | 
                        (mapping mapInstVar: #origin) valueSchema: Point.
                        (mapping mapInstVar: #corner) valueSchema: Point ];
      writeNil: true;
      nextPut: Rectangle new ].
-=-=-=-

What do you think?
Juraj

> On Nov 13, 2017, at 12:50, Juraj Kubelka <[email protected]> wrote:
> 
> Hi,
> 
> Please, how should I modify the mapping to be able to parse the following 
> example?
> 
> -=-=-=-
> rectangleJson := '{
>   "origin" : null,
>   "corner" : null
> }'.
> 
> (NeoJSONReader on: rectangleJson readStream)
>   mapInstVarsFor: Point;
>   for: Rectangle do: [ :mapping | 
>      (mapping mapInstVar: #origin) valueSchema: Point.
>      (mapping mapInstVar: #corner) valueSchema: Point ];
>   nextAs: Rectangle.
> -=-=-=-
> 
> I receive from a server JSON messages including null values. 
> Can we say use Point value schema or null? How? 
> 
> In the documentation I can see the example: 
> 
> -=-=-=-
> String streamContents: [ :stream |
>   (NeoJSONWriter on: stream)
>      mapAllInstVarsFor: Point;
>      writeNil: true;
>      nextPut: Point new ].
> -=-=-=-
> that produces {"x":null,"y":null}
> 
> But I do not see how to apply this for the following example: 
> -=-=-=-
> String streamContents: [ :stream |
>   (NeoJSONWriter on: stream)
>      mapAllInstVarsFor: Point;
>          for: Rectangle do: [ :mapping | 
>            (mapping mapInstVar: #origin) valueSchema: Point.
>            (mapping mapInstVar: #corner) valueSchema: Point ];
>      writeNil: true;
>      nextPut: Rectangle new ].
> -=-=-=-
> 
> Thanks,
> Juraj
> 
> 

Reply via email to