Skip to content

StackOverflowError serializing transient instances  #35

@sergiomichels

Description

@sergiomichels

With a simple domain class:

class Contact {
  String name
  String phone
  static constraints = {
     name blank:false, maxSize: 255
     email blank:false, maxSize: 255, unique: true
  }
}

And a controller save method:

def save() {
  Contact contact = new Contact(name: params.name, phone: params.phone, email: params.email)
  if(contact.save(flush:true)) {
    def pars = [success: false, contatos: contact]
    render pars as GSON
  } else {
    println contact.errors
    def pars = [success: false, contatos: contact] 
    render pars as GSON
  }
}

I'm getting StackOverflowError if I try to serialize a non-saved instance. This can be simulated in an Integration Test:

void testNewElement() {
  contactController.params.name = "teste"
  contactController.save()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions