apache / apache/grails-core

BindingHelper should be applied only on matched types

Open
#11,340 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

When mapping a class level BindUsing with a BindingHelper the helper is applied on all attributes, even it no match the type of helper. This is unusual since restrict the use of the funcionality to near 0.

This problem occurs on any grails version.

The binging helper
```groovy
package test

import grails.databinding.BindingHelper
import grails.databinding.DataBindingSource

import java.time.LocalDate
import java.time.format.DateTimeFormatter

class LocalDateBindingHelper implements BindingHelper {

private DateTimeFormatter formatter = DateTimeFormatter.ofPattern('dd/MM/yyyy')

@Override
LocalDate getPropertyValue(Object object, String propertyName, DataBindingSource source) {
println object[propertyName]

if (source[propertyName]) {
return LocalDate.parse(source[propertyName], formatter)
}
}
}
```

The command to bind
```groovy
@BindUsing(LocalDateBindingHelper)
class BindCommand {

LocalDate localDate1

LocalDate localDate2

Integer number

}
```

The binding helper is trying to convert the number property.

Contributor guide

Open the contributing guide

Research direction

Start at the data-binding entry points for BindUsing and BindingHelper, then reproduce the issue with the provided BindCommand and LocalDateBindingHelper examples. Trace how the helper is selected for each property; done means it runs for the LocalDate properties but not for the Integer number property.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.