Hi Esteban,

Your wish is my command ;-)

In #bleedingEdge you can now do:

  String streamContents: [ :stream |
    (NeoJSONWriter on: stream) 
      writeNil: true;
      mapAllInstVarsFor: Point;
      nextPut: Point new.

which will give you:

  {"x":null,"y":null}

instead of:

  {}

which remains the default.

===
Name: Neo-JSON-Core-SvenVanCaekenberghe.28
Author: SvenVanCaekenberghe
Time: 28 May 2014, 8:52:57.799163 pm
UUID: d6927f86-5b87-4ba2-99c1-cfe5b58ed22f
Ancestors: Neo-JSON-Core-SvenVanCaekenberghe.27

Added NeoJSONWriter #writeNil property, defaulting to false; when true, nil 
instance variables will be written as null by NeoJSONPropertyMapping, else they 
will be skipped
===
Name: Neo-JSON-Tests-SvenVanCaekenberghe.25
Author: SvenVanCaekenberghe
Time: 28 May 2014, 8:54:10.767617 pm
UUID: f1479d45-8d24-4bf6-b29a-aaf9f984c084
Ancestors: Neo-JSON-Tests-SvenVanCaekenberghe.24

Added NeoJSONWriterTests>>#testPointWriteNil

Added NeoJSONWriter #writeNil property, defaulting to false; when true, nil 
instance variables will be written as null by NeoJSONPropertyMapping, else they 
will be skipped
===

I hope this works for you.

Regards,

Sven

On 28 May 2014, at 18:06, Esteban A. Maringolo <emaring...@gmail.com> wrote:

> Hi all... and Sven ;-)
> 
> I'm mapping my objects with NeoJSONWriter, and I found it is not writing the 
> properties whose values are null.
> 
> NeoJSONPropertyMapping>>#writeObject: anObject on: jsonMapWriter
>       | value |
>       value := getter value: anObject.
>       value 
>               ifNotNil: [ jsonMapWriter writeKey: propertyName value: value 
> as: valueSchema ] 
> 
> 
> It is a good default (saves space, and cpu cycles). But in my case the 
> consumer of the JSON objects expect the objects to have all the attributes 
> previously defined.
> 
> Is there a way I can configure the mapper or the mapping to write null when 
> the value is nil?
> 
> Thank you!
> 
> 
> Esteban A. Maringolo


Reply via email to