Feature request: Bind input to Domain subclasses
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Task List
- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)
### Steps to Reproduce
1. Check out and run the example project
2. POST to /master with the following data:
```
{
"details": [
{"detailType": "FOO", "fooProperty": "foo"},
{"detailType": "BAR", "barProperty": "bar"}
]
}
```
### Expected Behaviour
I think Grails should know how to automatically create a FooDetail and a BarDetail by comparing the input discriminator property to the domain subclasses that are mapped.
### Actual Behaviour
Grails creates a Detail which is neither FooDetail nor BarDetail, based on the declared collection type in the Master class mapping. fooProperty and barProperty are ignored. To get a correct mapping, it is necessary to customize the binding (for example, by using a BindInitializer)
### Environment Information
- **Operating System**: Win7 x64
- **GORM Version:** 6.1.4.RELEASE
- **Grails Version (if using Grails):** 3.3.0.M2
- **JDK Version:** 1.8.0_131
### Example Application
- [https://github.com/rmorrise/bindToSubclassExample](https://github.com/rmorrise/bindToSubclassExample)
Contributor guide
Research direction
Start with the linked bindToSubclassExample application and its POST /master reproduction, then compare the current behavior with the BindInitializer customization mentioned in the issue. Done means input using detailType creates the corresponding FooDetail or BarDetail and preserves fooProperty or barProperty without custom binding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100