Package io.protostuff
Class CollectionSchema<V>
java.lang.Object
io.protostuff.CollectionSchema<V>
- All Implemented Interfaces:
Schema<Collection<V>>
- Direct Known Subclasses:
MessageCollectionSchema
A schema for standard jdk
collections
. Null values are not serialized/written.
If preserveNull
is false and your application relies on Object.equals(Object)
,
it will fail when a serialized collection contains null values.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
static interface
Creates newCollection
messages. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
This is used byCollectionSchema.MessageFactories.accept(String)
method.Factory for creatingCollection
messages.final Pipe.Schema
<Collection<V>> final boolean
-
Constructor Summary
ConstructorsConstructorDescriptionCollectionSchema
(boolean preserveNull) CollectionSchema
(CollectionSchema.MessageFactory messageFactory, boolean preserveNull) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
addValueFrom
(Input input, Collection<V> collection) Adds the value from the input into theCollection
.static final String
fieldName
(int number) static final int
fieldNumber
(String name) final String
getFieldName
(int number) Gets the field name associated with the number.final int
getFieldNumber
(String name) Gets the field number associated with the name.final boolean
isInitialized
(Collection<V> map) Returns true if there is no required field or if all the required fields are set.void
mergeFrom
(Input input, Collection<V> message) Deserializes a message/object from theinput
.final String
Returns the full name of the message tied to this schema.final String
Returns the simple name of the message tied to this schema.final Collection
<V> Creates the message/object tied to this schema.protected abstract void
transferValue
(Pipe pipe, Input input, Output output, int number, boolean repeated) Transfers the value from the input to the output.final Class
<? super Collection<V>> Gets the class of the message.void
writeTo
(Output output, Collection<V> message) Serializes a message/object to theoutput
.protected abstract void
writeValueTo
(Output output, int fieldNumber, V value, boolean repeated) Writes the value to the output.private void
writeWithNullTo
(Output output, Collection<V> message) private void
writeWithoutNullTo
(Output output, Collection<V> message)
-
Field Details
-
FIELD_NAME_VALUE
- See Also:
-
FIELD_NAME_NULL
- See Also:
-
MESSAGE_FACTORIES_NAMES
This is used byCollectionSchema.MessageFactories.accept(String)
method. Rather than iterating enums in runtime which can be an expensive way to do, caching all the enums as static property will be a good way. -
messageFactory
Factory for creatingCollection
messages. -
preserveNull
public final boolean preserveNull -
pipeSchema
-
-
Constructor Details
-
CollectionSchema
public CollectionSchema(boolean preserveNull) -
CollectionSchema
-
-
Method Details
-
fieldName
-
fieldNumber
-
addValueFrom
Adds the value from the input into theCollection
.- Throws:
IOException
-
writeValueTo
protected abstract void writeValueTo(Output output, int fieldNumber, V value, boolean repeated) throws IOException Writes the value to the output.- Throws:
IOException
-
transferValue
protected abstract void transferValue(Pipe pipe, Input input, Output output, int number, boolean repeated) throws IOException Transfers the value from the input to the output.- Throws:
IOException
-
getFieldName
Description copied from interface:Schema
Gets the field name associated with the number. This is particularly useful when serializing to different formats (Eg. JSON). When using numeric field names:return String.valueOf(number);
- Specified by:
getFieldName
in interfaceSchema<V>
-
getFieldNumber
Description copied from interface:Schema
Gets the field number associated with the name. This is particularly useful when serializing to different formats (Eg. JSON). When using numeric field names:return Integer.parseInt(name);
- Specified by:
getFieldNumber
in interfaceSchema<V>
-
isInitialized
Description copied from interface:Schema
Returns true if there is no required field or if all the required fields are set.- Specified by:
isInitialized
in interfaceSchema<V>
-
messageFullName
Description copied from interface:Schema
Returns the full name of the message tied to this schema. Allows custom schemas to provide a custom name other than typeClass().getName();- Specified by:
messageFullName
in interfaceSchema<V>
-
messageName
Description copied from interface:Schema
Returns the simple name of the message tied to this schema. Allows custom schemas to provide a custom name other than typeClass().getSimpleName();- Specified by:
messageName
in interfaceSchema<V>
-
typeClass
Description copied from interface:Schema
Gets the class of the message. -
newMessage
Description copied from interface:Schema
Creates the message/object tied to this schema.- Specified by:
newMessage
in interfaceSchema<V>
-
mergeFrom
Description copied from interface:Schema
Deserializes a message/object from theinput
.- Specified by:
mergeFrom
in interfaceSchema<V>
- Throws:
IOException
-
writeWithNullTo
- Throws:
IOException
-
writeWithoutNullTo
- Throws:
IOException
-
writeTo
Description copied from interface:Schema
Serializes a message/object to theoutput
.- Specified by:
writeTo
in interfaceSchema<V>
- Throws:
IOException
-