Execute query with enum

43 Views Asked by At

Working on Grails 6.1.1, I have this simple domain with an enum:

class ImageDataset extends UuidDomain {

    String name
    Date dateCreated
    String usernameCreated    
    DatasetType type

    static enum DatasetType {
        A, B, C
    } ...

I'm trying to do this query:

 List setElement = ImageDataset.executeQuery("select new Map(imgd.id as id, imgd.name as name, imgd.type as type ) from ImageDataset imgd")
  

What I get is this:

 "totalRecord": 1,
    "dataSet": [
        {
            "name": "acme",
            "id": "4028e4eb8c7d8573018c7d86e3660001",
            "type": {
                "enumType": "com.acme.ImageDataset$DatasetType",
                "name": "A"
            }
        }
    ] }

I get the whole enum object in return when I just want the string OBJ_DETECTION. If I write in the query type.name, oddly I get the field name of the domain in the example above acme instead of the enum name

0

There are 0 best solutions below