intercom-java
intercom-java copied to clipboard
cannot set user_id to null
Description
- It is not possible to clear a user_id value using the Java SDK
- Setting it to
null
does not send the data to the API
- Setting it to
- curl request works as expected and allows it
We support setting user_id to nil (tested it) I can understand the logic in wanting to remove user_ids from your users which we support.
Evidence
User user = User.find("598bd1ef1f40af9c8d64ceb0");
System.out.println("The user");
System.out.println(user);
user.setUserId(null);
System.out.println("Set user_id to null but before update");
System.out.println(user);
user = User.update(user);
System.out.println("After update");
System.out.println(user);
user = User.find("598bd1ef1f40af9c8d64ceb0");
System.out.println("After update retrieve by ID");
System.out.println(user);
If you run the above code the user id will not change
The root of the problem on this is that
- we are currently using the Jackson library for JSON generation
- and we have it set up to ignore null/unknown values
- so this should affect setting any field to null not just user_id
https://github.com/intercom/intercom-java/blob/fe3accf876fad1a3e3d8e9de49a87ce7a965035b/intercom-java/src/main/java/io/intercom/api/User.java#L17-L18
- Setting it to ignore unset values makes sense as if you update a record by only supplying a user_id value, we would not want to clear out the values of other fields like email
- We need to identify a way to detect explicitly setting a null value to be included in the JSON output to the API
- But there does not seem to be a direct way to identify an unset value compared to an explicitly set null value https://stackoverflow.com/questions/45397204/java-jackson-differentiate-between-null-and-unset-field
Will need more digging into possible solutions or workarounds