HalBuilder / halbuilder-json

HalBuilder JSON Support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow null values in property objects

raelg opened this issue · comments

commented

Hi,

Currently, null values in objects are not allowed, as JsonRepresentationReader uses Guava's ImmutableMap internally, which does not permit null keys or values. While it may be dubious practice to have a null value (as returning a null value from a Java Map may mean either the key does not exist or it does exist and is null), however, this is still valid JSON, which means it probably should be handled.

The simplest solution looks to be to remove the ImmutableMap.copyOf wrapper.

resource.withProperty(fieldName, field.isNull()
? null
: ( !field.isContainerNode() ? field.asText() : ImmutableMap.copyOf(mapper.readValue(field.toString(), Map.class))));

example failing HAL extract:

  {
    .... 
    "page": {
       "offset": null,
       "limit": null
     },
   ...
 }

Thanks.

This is currently now working under commit 5e2c752, with the switch away from Guava's ImmutableMaps in favour of using Javaslang persistent maps/lists thru out in the eventual 5.x release series.