Package com.google.gson.interceptors
Annotation Type Intercept
-
@Retention(RUNTIME) @Target(TYPE) public @interface Intercept
Use this annotation to indicate various interceptors for class instances after they have been processed by Gson. For example, you can use it to validate an instance after it has been deserialized from Json. Here is an example of how this annotation is used:Here is an example of how this annotation is used:
@Intercept(postDeserialize=UserValidator.class) public class User { String name; String password; String emailAddress; } public class UserValidator implements JsonPostDeserializer<User> { public void postDeserialize(User user) { // Do some checks on user if (user.name == null || user.password == null) { throw new JsonParseException("name and password are required fields."); } if (user.emailAddress == null) { emailAddress = "unknown"; // assign a default value. } } }
- Author:
- Inderjeet Singh
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description java.lang.Class<? extends JsonPostDeserializer>
postDeserialize
Specify the class that provides the methods that should be invoked after an instance has been deserialized.
-
-
-
Element Detail
-
postDeserialize
java.lang.Class<? extends JsonPostDeserializer> postDeserialize
Specify the class that provides the methods that should be invoked after an instance has been deserialized.
-
-