io.gsonfire.gson.HooksInvoker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gson-fire Show documentation
Show all versions of gson-fire Show documentation
A java library that adds some very useful features to Gson, like Date serializing to unix timestamp or RFC3339, method (getter) serialization, pre and post processors and many more. Check out the documentation to learn how to use it!
package io.gsonfire.gson;
import io.gsonfire.annotations.PostDeserialize;
import io.gsonfire.annotations.PreSerialize;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* @autor: julio
*/
public class HooksInvoker {
private MethodInspector inspector = new MethodInspector();
public HooksInvoker(){
}
public void preSerialize(Object obj){
invokeAll(obj, PreSerialize.class);
}
public void postDeserialize(Object obj){
invokeAll(obj, PostDeserialize.class);
}
private void invokeAll(Object obj, Class extends Annotation> annotation){
for(Method m: inspector.getAnnotatedMethods(obj.getClass(), annotation)){
try {
m.invoke(obj);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}