Created
July 10, 2017 09:54
-
-
Save houdq/e877dc693033c776530f96b12df5e41f to your computer and use it in GitHub Desktop.
java/groovy bean copy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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