apache / apache/grails-core

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

Open
#14,399 0 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-mongodb
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

Hi Grails Team,

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

```
class Company implements MongoEntity {
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 {

@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.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the RestfulController save(Company company) binding path and the request.JSON behavior described in the issue. Check how additional JSON fields are expected to reach gorm_dynamic_attributes and define done as those fields being persisted and returned; no file or test is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
api, backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
18/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.