Skip to content

Instantly share code, notes, and snippets.

@houdq
Created July 10, 2017 09:54
Show Gist options
  • Save houdq/e877dc693033c776530f96b12df5e41f to your computer and use it in GitHub Desktop.
Save houdq/e877dc693033c776530f96b12df5e41f to your computer and use it in GitHub Desktop.
java/groovy bean copy
@CompileStatic
class BeanUtil {
static def copyProperties(source, target) {
this.copyProperties(source, target, [] as String[])
}
static def copyProperties(source, target, String[] ex) {
def exludeList = ['class', 'metaClass']
exludeList.addAll(ex)
source.properties.each { key, value ->
if (target.hasProperty((String) key) && !(key in exludeList)) {
target[(String) key] = value
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment