grails-data-mapping icon indicating copy to clipboard operation
grails-data-mapping copied to clipboard

Auto Mapping of Dynamic fields in RestfulController POST (save) method

Open theiosdevguy opened this issue 6 years ago • 1 comments

Hi Grails Team,

How do I enable RestfulController to auto-map the dynamic fields to domain classes implementing MongoEntity? I have a domain class as below:

class Company implements MongoEntity<Company> {
    String id = UUID.randomUUID().toString()
    String name
    String email
    String phone
}

And I have a RestfulController setup for CRUD operations as below

class CompanyController extends RestfulController<Company> {

@Transactional
    def save(Company company) {
        if(company.hasErrors()) {
            respond company.errors
        }
        else {
            company.insert(flush:true)
            respond company, status: CREATED
        }
    }
}

When I POST a request with some additional JSON fields, how do I get them auto-mapped to gorm_dynamic_attributes ? Currently the company object does not return any information on the dynamic attributes. Another problem I am facing is that request.JSON is also null so I cannot manually map either.

Please suggest.

Thanks.

theiosdevguy avatar Apr 24 '19 15:04 theiosdevguy

+1

ekimeel avatar Feb 11 '20 10:02 ekimeel