I have a ConfigInstance class which contains a password and a password_hash.
Now I want to serialize the object using gson but exclude
Here's a very simple solution with just one line of code, without any @Expose annotation or exclusion strategy.
The default behaviour that is implemented in Gson is that null object fields are ignored. So, all you need to do is set the password field to null before serializing.
map.setPassword(null); // or map.password = null;
String jsonConfig = gson.toJson(map); // This won't serialize null password field