Groovy Documentation

groovy.transform
[Java] Annotation Type AutoExternalize

java.lang.Object
  groovy.transform.AutoExternalize

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@GroovyASTTransformationClass("org.codehaus.groovy.transform.AutoExternalizeASTTransformation")
public @interface AutoExternalize

Note: This annotation is currently experimental! Use at your own risk!

Class annotation used to assist in the creation of Externalizable classes. The @AutoExternalize annotation instructs the compiler to execute an AST transformation which adds writeExternal() and readExternal() methods to a class and adds Externalizable to the interfaces which the class implements. The writeExternal() method writes each property (or field) for the class while the readExternal() method will read each one back in the same order. Properties or fields marked as transient are ignored.

Example usage:

 import groovy.transform.*
 @AutoExternalize
 class Person {
   String first, last
   List favItems
   Date since
 }
 
Which will create a class of the following form:
 class Person implements Externalizable {
   ...
   public void writeExternal(ObjectOutput out) throws IOException {
     out.writeObject(first)
     out.writeObject(last)
     out.writeObject(favItems)
     out.writeObject(since)
   }

   public void readExternal(ObjectInput oin) {
     first = oin.readObject()
     last = oin.readObject()
     favItems = oin.readObject()
     since = oin.readObject()
   }
   ...
 }
 
Authors:
Paul King
Since:
1.8.0


 
Optional Element Summary
java.lang.String excludes

Comma separated list of property names to exclude from externalizing.

boolean includeFields

Include fields as well as properties when externalizing.

 
Method Summary
 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Element Detail

excludes

public java.lang.String[] excludes
Comma separated list of property names to exclude from externalizing. For convenience, a String with comma separated names can be used in addition to an array (using Groovy's literal list notation) of String values. @default {}


includeFields

public boolean includeFields
Include fields as well as properties when externalizing. @default false


 

Groovy Documentation