NeoJSON. Allowing null or an object

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

NeoJSON. Allowing null or an object

Juraj Kubelka
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 | Threaded
Open this post in threaded view
|

Re: NeoJSON. Allowing null or an object

Juraj Kubelka
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 <[hidden email]> 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 | Threaded
Open this post in threaded view
|

Re: NeoJSON. Allowing null or an object

Sven Van Caekenberghe-2
Juraj,

Check out:

===
Name: Neo-JSON-Core-SvenVanCaekenberghe.46
Author: SvenVanCaekenberghe
Time: 13 November 2017, 6:59:13.995868 pm
UUID: f412799a-431a-0d00-850e-5c3c05ce5378
Ancestors: Neo-JSON-Core-SvenVanCaekenberghe.45

Fix the NeoJSONWriter>>#writeNil: true option by adding a short circuit to NeoJSONWriter>>nextPut:as: (as reported by Juraj Kubelka)

Add #testRectanglePointsWithNil
===
Name: Neo-JSON-Tests-SvenVanCaekenberghe.44
Author: SvenVanCaekenberghe
Time: 13 November 2017, 6:59:37.365898 pm
UUID: 35acdd9b-431a-0d00-850f-878405ce5378
Ancestors: Neo-JSON-Tests-SvenVanCaekenberghe.43

Fix the NeoJSONWriter>>#writeNil: true option by adding a short circuit to NeoJSONWriter>>nextPut:as: (as reported by Juraj Kubelka)

Add #testRectanglePointsWithNil
===

These should fix your last case. I used your example in the new unit test.

Note that #allowNil on a mapper is about reading, not writing.

HTH,

Sven

> On 13 Nov 2017, at 17:10, Juraj Kubelka <[hidden email]> wrote:
>
> 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 <[hidden email]> 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 | Threaded
Open this post in threaded view
|

Re: NeoJSON. Allowing null or an object

Juraj Kubelka
Hi Sven,

thank you for the fix!

I understand that #allowNil is about reading, while #writeNil: is about writing.
I use the same mapping for the reader and writer. This is why I spotted the case.

Thanks!
Juraj

> On Nov 13, 2017, at 16:30, Sven Van Caekenberghe <[hidden email]> wrote:
>
> Juraj,
>
> Check out:
>
> ===
> Name: Neo-JSON-Core-SvenVanCaekenberghe.46
> Author: SvenVanCaekenberghe
> Time: 13 November 2017, 6:59:13.995868 pm
> UUID: f412799a-431a-0d00-850e-5c3c05ce5378
> Ancestors: Neo-JSON-Core-SvenVanCaekenberghe.45
>
> Fix the NeoJSONWriter>>#writeNil: true option by adding a short circuit to NeoJSONWriter>>nextPut:as: (as reported by Juraj Kubelka)
>
> Add #testRectanglePointsWithNil
> ===
> Name: Neo-JSON-Tests-SvenVanCaekenberghe.44
> Author: SvenVanCaekenberghe
> Time: 13 November 2017, 6:59:37.365898 pm
> UUID: 35acdd9b-431a-0d00-850f-878405ce5378
> Ancestors: Neo-JSON-Tests-SvenVanCaekenberghe.43
>
> Fix the NeoJSONWriter>>#writeNil: true option by adding a short circuit to NeoJSONWriter>>nextPut:as: (as reported by Juraj Kubelka)
>
> Add #testRectanglePointsWithNil
> ===
>
> These should fix your last case. I used your example in the new unit test.
>
> Note that #allowNil on a mapper is about reading, not writing.
>
> HTH,
>
> Sven
>
>> On 13 Nov 2017, at 17:10, Juraj Kubelka <[hidden email]> wrote:
>>
>> 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 <[hidden email]> 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
>>>
>>>
>>
>
>