@Target(value={FIELD,METHOD}) @Retention(value=RUNTIME) public @interface PortableProperty
value()
and
codec()
can be explicitly specified they can be
determined by classes that use this annotation. Hence these attributes
serve as hints to the underlying parser.public abstract int value
PofWriter
public abstract Class<?> codec
Codec
to use to override the default behavior in serializing
and deserializing a property.
The Class specified must have a no-arg constructor and must implement one of:
Collection
interface.
A Codec implementation that supports the Collection
type will be used.Map
interface.
A Codec implementation that supports the Map
type will be used.LongArray
interface.
A Codec implementation that supports the LongArray
type will be used.
{@literal @}PortableProperty(value = 0, codec = LinkedList.class)
protected List m_listPeople;
A more complex example could be to specify a custom Codec implementation:
{@literal @}PortableProperty(value = 0, codec = MyArrayListCodec.class)
protected List m_listPeople;
class MyArrayListCodec
implements Codec
{
public Object decode(PofReader in, int index)
throws IOException
{
in.readCollection(index, new ArrayList(16);
}
...
}