I want to store whether something should be a String or an Integer in the database. My fantasy would be something like this:
Class FantasyClass{
String someInfo
Class whichClass
}
And then I could call it like this:
def thisThing = new FantasyClass(someInfo:'lalala',whichClass:String)
Is there any workaround to achieve this functionality?
Where I could go like:
def getAThing = FantasyClass.get(1)
assert getAThing.whichClass == String
assert 'thisIsAString' instanceof getAThing.whichClass //THIS IS WHAT I REALLLLLLY WANT!!!
You can use the
asTypemethodHere’s a more generic example:
And you can add a helper method to the domain class that will convert the String to the specified type for you:
and then you can do this: