Let say we have a server that manage a library in which you can add a book, find a book and get all the books. The server code will probably look like this:
| Code Block |
|---|
| java |
|---|
| title | BookService.groovy |
|---|
|
class BookService {
private List allBooks = new ArrayList()
Book findBook(String isbn) {
for (book in allBooks) {
if (book.isbn == isbn) return book
}
return null
}
void addBook(Book book) {
allBooks.add(book)
}
Book[] getBooks() {
return (Book[])allBooks.toArray(new Book[allBooks.size()])
}
}
|
with the class Book being something like that.
| Code Block |
|---|
|
class Book {
String author
String title
String isbn
}
|
To ignore the metaClass property a custom type mapping must be defined (for details refer to Aegis Binding).
| Code Block |
|---|
|
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns:sample="http://DefaultNamespace">
<mapping name="sample:Book">
<property name="metaClass" ignore="true"/>
</mapping>
</mappings>
|
However, if you compile custom data types from Java the bytecode won't contain a metaClass property and, hence, there is no need to define a custom mapping.