Start a new topic

Data store : null management


I'm using the Kinvey console to update values in the data store and I want to represent "null" values.

For instance, if I have a "Car" collection with 2 columns : "doors" (integer) and "name" (string).

The json could be :

> {"doors":null,

> "name":null}

In the Java bean, we have :

> private Integer doors;

> private String name;

After loading data :

> "doors" is an Integer equal to 0

> "name" is a String equal to null

Could you tell me what is the best way to manage null values using the Kinvey console ?

Thank you.

Hey, this is a combination of the GSON parser as well as the json specification.

If you leave the `Strings` absent from the JSON payload, then they will resolve to `null` on the Client, however this will not work with `Integers`, with will default to 0. It looks like GSON treats all numbers as `int`s, which cannot be null.

As a workaround, if you need null values for numbers, you can either add a boolean flag to indicate if a value has been set `doorsSet: false`, or you can treat all numbers as Strings and then do a `Integer.valueOf(...)` to get the numerical value.

Hello Edward, thank you for your explanation.

My solution is ugly : if(myBean.getField() == 0) myBean.setField(null);

I'm not fond of theses solutions :(
Login or Signup to post a comment