mendix / RestServices

REST service module for Mendix. Supports consuming and publishing REST based services and real-time data synchronization. Supports JSON, form-encoded, multipart and binary data transport.
Apache License 2.0
31 stars 46 forks source link

Null value in enum and numbers #64

Closed ppoetsma closed 8 years ago

ppoetsma commented 9 years ago

Hi,

Deserializing JSON null values in enumerations and numbers (int, long, float, etc) is not supported. Why is that and can it be changed?

Regards, Paul

mweststrate commented 9 years ago

As far as I can see from the code it is supported except for booleans. Are you using the latest version? Otherwise can you provide some more details?

Anyway, the code you are interested is located here: https://github.com/mendix/RestServices/blob/master/javasource/restservices/util/JsonDeserializer.java#L169

ppoetsma commented 9 years ago

Oops, I mean serialization; keep on mixing the two. We are on version 1.4.2 because we are still using Mx 5.8.1. Soon we will upgrade but it is hard to keep up. Per version 1.4.2 null values are allowed for deserialization but not serialization.

My app provides webservices but when an integer gets null this is the response: "Failed to serve POST : Invalid JSON: JSONObject["SomeID"] is not an int.". And skipping the attribute is not an option because null is a value as well.

mweststrate commented 9 years ago

Hi @ppoetsma

This can be fixed by altering: https://github.com/mendix/RestServices/blob/master/javasource/restservices/util/JsonSerializer.java#L166 (put null instead of throw)

and to make sure the generated json schema also still match: https://github.com/mendix/RestServices/blob/master/javasource/restservices/util/JSONSchemaBuilder.java#L123 (basically, wrap orNull around the corresponding types)

mweststrate commented 8 years ago

(almost) published as part of the 2.0 release

ppoetsma commented 8 years ago

Thanks!