Skip to content

Custom annotation supported based on Gson. It validates the required fields marked with the annotation and does the strict parsing.

Notifications You must be signed in to change notification settings

rayworks/AnnotationParser

Repository files navigation

AnnotationParser

A custom annotation supported based on Gson. It validates the required fields marked with the annotation and does the strict parsing. Inspired by http://stackoverflow.com/questions/14242236/let-gson-throw-exceptions-on-wrong-types/14245807#14245807

Usage:

  • Add the specified annotation "JsonRequired" for required field :
public class TestAnnotationBean {
    @JsonRequired
    public String foo;

    public String bar;
}
  • Register the deserializer :
gson = new GsonBuilder()
     .registerTypeHierarchyAdapter(TestAnnotationBean.class,
             new AnnotatedDeserializer<TestAnnotationBean>())
     .create();
  • Parse String as an object.

About

Custom annotation supported based on Gson. It validates the required fields marked with the annotation and does the strict parsing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages