JSON null field: blank quotes, null value or delete field?

I (the Java server developer) and two of my colleagues (iOS and Android developers) have a problem (actually a dispute).

The opinion of mobile developers: I need to replace in the JSON that they retrieve from my server, all empty fields (this field may be a field for my custom object) for empty quotes (note that Java is a language with static types). The reason for this: they cannot find a solution that allows me to deserialize my JSON (object mapping) if it has zero values.

My opinion: java serializers cannot be manipulated at the value level, only at the type level. Therefore, I can write serializer only for some class. And, I don’t know why, but the empty quotes instead of zero seems to me a very bad practice, which can create a lot of problems in the future.

+4
source share
3 answers

Suppose you are trying to infer types into your fields, so a hypothetical named fusually contains numbers.

This makes sense to me because you combine a strongly typed language with one that is not.

, f null , null? .

, , , . , , , , , , !!

, , null, .

, , , , , null.

, null, , , . , - , api .

+2

null '' (, Java, REST API). null , .

:

  • , .

  • , .

  • API, , , .

(, Jackson ObjectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false)).

+1

null '' . , Gson , . ,

0

Source: https://habr.com/ru/post/1611886/


All Articles