2

Given these domain classes:

class Person {
    Long id
    String name

    static hasMany = [aliases: PersonAlias]
}

class PersonAlias {
    Person person
    Long id
    String name
}

I try to do a straight-forward round trip load/save through JSON land:

Person p = Person.get(20005353);
def json = p as JSON
def str = json as String
def map = JSON.parse(str)
p.properties = map
p.save(flush:true)

which produces this JSON

{
  "id": 20005353,
  "name": "John Smith",
  "class": "Person",
  "aliases":
  [
    {
      "class": "PersonAlias",
      "id": 99,
      "name": "J. Smith"
    }
  ]
}

And fails with this error:

grails.validation.ValidationErrors: 1 errors Field error in object 'heavymeta.Person' on field 'aliases': rejected value [[]]; codes [typeMismatch.heavymeta.Person.aliases,typeMismatch.aliases,typeMismatch.java.util.Set,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [heavymeta.Person.aliases,aliases]; arguments []; default message [aliases]]; default message [Failed to convert property value of type 'org.codehaus.groovy.grails.web.json.JSONArray' to required type 'java.util.Set' for property 'aliases'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.LinkedHashMap] to required type [heavymeta.PersonAlias] for property 'aliases[0]': no matching editors or conversion strategy found]

Why does this fail, and is there a way to make it work?

1 Answer 1

1

I can give you a little suggestion (=. Check params in debug mode in update action(if you haven't generated views and controller for domain class run in console generate-all Person). Take a look to params.aliases you'll find it as list of ids. Try the same.

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

Comments

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.