julman99 / gson-fire

A java library that adds some very useful features to Gson, like Date serializing to unix timestamp or RFC3339, method (getters) serialization, pre/post processors and many others. Check out the documentation to learn how to use it!
http://gsonfire.io
Other
229 stars 37 forks source link

Centralized all annotation inspection in one class #17

Closed julman99 closed 9 years ago

julman99 commented 9 years ago

During development of #16 I noticed that we had different logics around the project to retrieve annotated fields or methods from a class.

This PR unifies all that logic in a new abstract class called AnnotationInspector. This class is based on the previous FieldInspector, but now it does not have any synchronized keyword and takes advantage of the ConcurrentMap.putIfAbsent method.

Also, AnnotationInspector allows mapping of the fields to an arbitrary class, useful for the MappedMethod type we use to handle @ExposeMehtodResult

joaocpsantos commented 9 years ago

:+1: Merging the getAnnotatedFields and Methods to Members is nice! Only problem is that if the consumer needs to know the type, may have to do an instanceof, but generally it will only need the annotation, so, should not be a problem.

julman99 commented 9 years ago

@joaocpsantos, the thing is that it is an abstract class, and then there are two implementations, MethodInspector and FieldInspector, each of these return the appropriate class. AnnotationInspector is just to encapsulate the cache logic because it is quite complicated and it was duplicated