Gson: How to exclude specific fields from Serialization without annotations

后端 未结 15 1651
后悔当初
后悔当初 2020-11-22 05:39

I\'m trying to learn Gson and I\'m struggling with field exclusion. Here are my classes

public class Student {    
  private Long                id;
  privat         


        
15条回答
  •  天涯浪人
    2020-11-22 06:28

    Or can say whats fields not will expose with:

    Gson gson = gsonBuilder.excludeFieldsWithModifiers(Modifier.TRANSIENT).create();
    

    on your class on attribute:

    private **transient** boolean nameAttribute;
    

提交回复
热议问题