apache / apache/grails-core

Class-level @BindUsing result is not used for child entities in a collection

Open
#14,607 0 comments 0 reactions 0 assignees View on GitHub
relates-to: gorm
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. Start with the previous example (linked below)
2. On the `Detail` domain class, add a class-level annotation: `@BindUsing(DetailBindHelper)`
3. Create a `DetailBindHelper` class that returns: `new FooDetail(fooProperty: source['fooProperty'])`
4. POST to /master with the following data:
```
{
"details": [
{"detailType": "FOO", "fooProperty": "foo"}
]
}
```

### Expected Behaviour

`BindingHelper#getPropertyValue()` should be invoked only once for each child object converted. The object returned from this method should be added to the collection on the parent object.

### Actual Behaviour

`BindingHelper#getPropertyValue()` seems to be invoked twice for each child object in the input.

The object returned from this method is never used in the calling code.
See: `SimpleDataBinder#convert(Class, value)`, lines 782-784

The conversion result ends up being a blank object.

### Environment Information

- **Operating System**: Win7 x64
- **GORM Version:** 6.1.6.RELEASE
- **Grails Version (if using Grails):** 3.3.0
- **JDK Version:** 1.8.0_131

### Example Application

- [https://github.com/rmorrise/bindToSubclassExample](https://github.com/rmorrise/bindToSubclassExample)

Contributor guide

Open the contributing guide

Research direction

Start with SimpleDataBinder#convert(Class, value), especially lines 782-784, and compare it with the reproduction in the linked bindToSubclassExample application. Trace the class-level @BindUsing path for child entities in a collection. Done means each child invokes BindingHelper#getPropertyValue() once and the returned object is added to the parent collection.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.