Where answers come from

Some pages can ask a language model questions. Set this up once; your choice is remembered in this browser for the whole site.

Model source
Use another source instead
You sign in on OpenRouter; it gives this page a key for your account.

More fun with Groovy and Reflection API

Originally published .

This time in a TagLib I need to see all the properties of a domain class but I don’t want to look at anything that isn’t sent to hibernate.


import java.lang.reflect.Modifier

static getFields(obj) {

      def names = []

      def fields = obj.getClass().declaredFields

      fields.each({ field ->

       if(!field.synthetic)

        if(!Modifier.isStatic(field.modifiers))

         if(!Modifier.isTransient(field.modifiers)) {

          names.add(field.name.toString())

                                 }

      })

      return names

    }

… in another method I’ll filter out the Closures by checking against Closure.class and the property’s class.

Explore the map · Browse by topic and date