Skip to content

Instantly share code, notes, and snippets.

@Alotor
Last active August 29, 2015 14:14
Show Gist options
  • Save Alotor/c3077f79a9c7c1e2c581 to your computer and use it in GitHub Desktop.
Save Alotor/c3077f79a9c7c1e2c581 to your computer and use it in GitHub Desktop.
Databinding
class Test {
String a
String b
String c
}
class Test2 {
String a
String b
String c
String d
}
def tmp = new Test(a: "asdf", b: "ddd", c: "eeee")
def tmp2 = new Test2(tmp.properties - [class: Test])
println tmp2.properties
import groovy.transform.ToString
trait Mergeable {
def leftShift(Object value) {
println "$this << $value"
this.properties.each {
if (value.properties.containsKey(it.key) && it.key != "class") {
this."${it.key}" = value."${it.key}"
}
}
return this
}
}
@ToString
class Test {
String a
String b
String c
}
@ToString
class Test2 implements Mergeable {
String b
String c
String d
}
def tmp = new Test(a: "asdf", b: "ddd", c: "eeee")
def tmp2 = new Test2() << tmp
println tmp2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment