Package com.google.gson.interceptors
Annotation Type 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:
invalid input: '@'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 ElementsModifier and TypeRequired ElementDescriptionClass
<? extends JsonPostDeserializer> Specify the class that provides the methods that should be invoked after an instance has been deserialized.
-
Element Details
-
postDeserialize
Class<? extends JsonPostDeserializer> postDeserializeSpecify the class that provides the methods that should be invoked after an instance has been deserialized.
-