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

com.atlassian.json.schema.util.ReflectionUtil Maven / Gradle / Ivy

There is a newer version: 1.1.3
Show newest version
package com.atlassian.json.schema.util;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class ReflectionUtil
{
    public static List getPropertiesForJson(Class clazz)
    {
        List fieldsForJson = new ArrayList();

        populateFields(clazz,fieldsForJson);

        return fieldsForJson;
    }
    
    private static void populateFields(Class clazz,List fieldsForJson)
    {
        if(null == clazz || Object.class.equals(clazz))
        {
            return;
        }
        
        for (Field field : clazz.getDeclaredFields())
        {
            int mods = field.getModifiers();

            if (!Modifier.isAbstract(mods) && !Modifier.isStatic(mods) && !Modifier.isTransient(mods))
            {
                field.setAccessible(true);
                fieldsForJson.add(field);
            }
        }
        
        populateFields(clazz.getSuperclass(),fieldsForJson);
    }

    public static boolean isParameterizedType(Type type)
    {
        return (type instanceof ParameterizedType);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy