2

I'm attempting to convert my Map<String, TableEntry> to JSON in my controller as follows

def index() {
        // get tables
        JSON.use('deep')
        render(tables) as JSON
    }

My TableEntry is a non-domain class as I do not wish to persist it

class TableEntry {
    String teamName
    Integer gamesPlayed = 0
    Integer gamesWon = 0
    Integer gamesDrawn = 0
    Integer gamesLost = 0
    Integer points = 0

    // other methods

However, when my JSON is rendered in the client, I get the following:

'Team A':TableEntry@3b52fb28, 'Team Z':TableEntry@44e71d85

How do I get this to convert fully?

1 Answer 1

1

Your render statement is incorrect. You have:

    render(tables) as JSON

However, it should read:

    render tables as JSON

By wrapping the variable "tables" in parenthesis, the render is happening before you can cast "tables" to JSON.

Sign up to request clarification or add additional context in comments.

1 Comment

I've had problems with that syntax too, depending on the expression complexity, so I usually use render(tables as JSON) to make sure as is applied correctly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.