Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BindingHelper should be applied only on matched types #11340

Open
volnei opened this issue Jun 4, 2019 · 0 comments
Open

BindingHelper should be applied only on matched types #11340

volnei opened this issue Jun 4, 2019 · 0 comments

Comments

@volnei
Copy link

volnei commented Jun 4, 2019

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

package test

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

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

class LocalDateBindingHelper implements BindingHelper<LocalDate> {

	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

@BindUsing(LocalDateBindingHelper)
class BindCommand {

	LocalDate localDate1 

	LocalDate localDate2

	Integer number 

}

The binding helper is trying to convert the number property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant