'GSON serialize the field only in certain cases

Is it possible to serialize a field for certain cases? I am using a POJO to create a JSON and calling a no-arg constructor and then set up the Object via setter methods. When salary is not set, I get 0 as the default value. Since "employee" is used many times in the same JSON file, I can not use "transient" or "Expose". I suppose writing an ExclusionStrategy would ignore the "employee" and remove it from the whole JSON as well.

  {
   "company":{
      "employee":{
         "name":"x",
         "salary":50
      }
   },
   "boss":{
      "employee":{
         "name":"y"
      }
   }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source