com.google.gson.interceptors
@Retention(value=RUNTIME) @Target(value=TYPE) public @interface Intercept
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.
}
}
}
| Modifier and Type | Required Element and Description |
|---|---|
java.lang.Class<? extends JsonPostDeserializer> |
postDeserialize
Specify the class that provides the methods that should be invoked after an instance
has been deserialized.
|
public abstract java.lang.Class<? extends JsonPostDeserializer> postDeserialize