agrestio / agrest

Server-side Java REST Framework for easy access to data graphs from various backends
https://agrest.io
Apache License 2.0
80 stars 34 forks source link

EntityUpdate.getToMany(String) should return null if the key is not a part of update #638

Closed andrus closed 1 year ago

andrus commented 1 year ago

Per recent EntityUpdate refactoring (#636),getToMany(String) returns an empty list if the key is not a part of the update. On the one hand, it follows the convention of not returning null collections, on the other, null and [] in the context of relationship update means 2 different things ("no update" vs "remove all related objects"), so let's change the semantics to return null if there's no update key.

And another aspect... Currently, there is a hack in the parser that sets an array of IDs to a single "null" element to indicate "unset everything". Instead, we should use null and [] as a designators for "toManyIds", and add methods to init empty arrays of related ids|updates when parsing.