Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Gson can do this in a few ways, marking a field transient, using a custom DeserializationExclusionStrategy and usage of the @Expose annotation (although this annotation is the inverse of your use case)</p> <p>That being said, your example case seems like it works fine.</p> <p>see the section on the user guide. Full of useful stuff! <a href="https://sites.google.com/site/gson/gson-user-guide" rel="nofollow">https://sites.google.com/site/gson/gson-user-guide</a></p> <p><strong>Excluding Fields From Serialization and Deserialization</strong> </p> <blockquote> <p>Gson supports numerous mechanisms for excluding top-level classes, fields and field types. Below are pluggable mechanism that allow field and class exclusion. If none of the below mechanism satisfy your needs then you can always use custom serializers and deserializers.</p> <p>Java Modifier Exclusion</p> <p>By default, if you mark a field as transient, it will be excluded. As well, if a field is marked as "static" then by default it will be excluded. If you want to include some transient fields then you can do the following:</p> <p>import java.lang.reflect.Modifier;</p> <p>Gson gson = new GsonBuilder() .excludeFieldsWithModifier(Modifier.STATIC) .create();</p> <p>NOTE: you can use any number of the Modifier constants to "excludeFieldsWithModifier" method. For example: Gson gson = new GsonBuilder() .excludeFieldsWithModifier(Modifier.STATIC, Modifier.TRANSIENT, Modifier.VOLATILE) .create(); Gson's @Expose</p> <p>This feature provides a way where you can mark certain fields of your objects to be excluded for consideration for serialization and deserialization to JSON. To use this annotation, you must create Gson by using new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(). The Gson instance created will exclude all fields in a class that are not marked with @Expose annotation.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload