I'm trying to use DataBindingUtils.bindObjectToInstance(object, source) to copy properties from one object to another using this code (which can be run in the Grails console):
import org.codehaus.groovy.grails.web.binding.DataBindingUtils
class Source {
String foo = 'foo'
String bar = 'bar'
}
class Target {
String foo
String bar
}
def s = new Source()
def t = new Target()
def result = DataBindingUtils.bindObjectToInstance(t, s)
assert t.foo == 'foo'
assert t.bar == 'bar'
But the assertions are failing because the properties of t are null, why?
The data binder (below) in Grails has only implemented binding for a select subset of object types, namely Maps and Web Requests. So binding two arbitrary objects isn't implemented.
https://github.com/grails/grails-core/blob/master/grails-web/src/main/groovy/org/codehaus/groovy/grails/web/binding/DataBindingUtils.java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With