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:

 &#64Intercept(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.
     }
   }
 }
 

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Specify the class that provides the methods that should be invoked after an instance has been deserialized.
  • Element Details

    • postDeserialize

      Class<? extends JsonPostDeserializer> postDeserialize
      Specify the class that provides the methods that should be invoked after an instance has been deserialized.