Created
September 29, 2011 07:46
-
-
Save dmitric/1250213 to your computer and use it in GitHub Desktop.
MapBackedBeanUsage
This file contains hidden or 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
def mappings = [ | |
[csvProperty: "item name", classProperty: "name"], | |
[csvProperty: "cost in $", classProperty: "cost", conversion: CSVBeanBuilder.STRING_TO_DOUBLE], | |
[csvProperty: "count", classProperty: "itemCount", conversion: CSVBeanBuilder.STRING_TO_INT], | |
[csvProperty: "date", classProperty: "purchaseDate", conversion: CSVBeanBuilder.STRING_TO_DATE], | |
] | |
CSVBeanBuilder.loadAs(MapBackedBean.class, csvText, mappings).each { | |
transaction -> | |
assert(transaction.name == transaction.getName() && transaction.getName() == transaction["name"] ) | |
assert(transaction.cost == transaction.getCost() && transaction.getCost() == transaction["cost"] ) | |
assert(transaction.itemCount == transaction.getItemCount() && transaction.getItemCount() == transaction["itemCount"] ) | |
assert(transaction.purchaseDate == transaction.getPurchaseDate() && transaction.purchaseDate == transaction["purchaseDate"] ) | |
} | |
//And now we have a list of objects, where all of the fields/method call points/property call points were created | |
//dynamically, based solely on the classProperty fields in the mappings list! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment