intercom-java icon indicating copy to clipboard operation
intercom-java copied to clipboard

cannot set user_id to null

Open choran opened this issue 7 years ago • 1 comments

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
  • 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

choran avatar Nov 24 '17 12:11 choran

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

thewheat avatar Jan 24 '18 17:01 thewheat