All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.gsonfire.gson.HooksInvoker Maven / Gradle / Ivy

Go to download

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!

There is a newer version: 1.9.0
Show newest version
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 annotation){
        for(Method m: inspector.getAnnotatedMethods(obj.getClass(), annotation)){
            try {
                m.invoke(obj);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy