vendredi 23 octobre 2020

Best Way to Convert All Attributes On Java Object With Empty Strings to Null

I've been searching around but haven't been able to find a good example of this. I have a POJO such as

public class SomeObject implements Serializable {
   private String name;
   private String residence;
   private String phone;

   // standard getters and setters
}

I am trying to find a better, more dynamic way using reflection to find if any of those attributes contain empty strings e.g. "", and set those attributes to null. I know I could manually loop through the object and look at each attribute individually and set it that way, but I figure there has to be a better programmatic solution than that. Would anyone be able to help me with this?





Aucun commentaire:

Enregistrer un commentaire