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 enumstatic interfaceCreates newCollectionmessages. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final StringThis is used byCollectionSchema.MessageFactories.accept(String)method.Factory for creatingCollectionmessages.final Pipe.Schema<Collection<V>> final boolean -
Constructor Summary
ConstructorsConstructorDescriptionCollectionSchema(boolean preserveNull) CollectionSchema(CollectionSchema.MessageFactory messageFactory, boolean preserveNull) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidaddValueFrom(Input input, Collection<V> collection) Adds the value from the input into theCollection.static final StringfieldName(int number) static final intfieldNumber(String name) final StringgetFieldName(int number) Gets the field name associated with the number.final intgetFieldNumber(String name) Gets the field number associated with the name.final booleanisInitialized(Collection<V> map) Returns true if there is no required field or if all the required fields are set.voidmergeFrom(Input input, Collection<V> message) Deserializes a message/object from theinput.final StringReturns the full name of the message tied to this schema.final StringReturns the simple name of the message tied to this schema.final Collection<V> Creates the message/object tied to this schema.protected abstract voidtransferValue(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.voidwriteTo(Output output, Collection<V> message) Serializes a message/object to theoutput.protected abstract voidwriteValueTo(Output output, int fieldNumber, V value, boolean repeated) Writes the value to the output.private voidwriteWithNullTo(Output output, Collection<V> message) private voidwriteWithoutNullTo(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 creatingCollectionmessages. -
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:SchemaGets 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:
getFieldNamein interfaceSchema<V>
-
getFieldNumber
Description copied from interface:SchemaGets 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:
getFieldNumberin interfaceSchema<V>
-
isInitialized
Description copied from interface:SchemaReturns true if there is no required field or if all the required fields are set.- Specified by:
isInitializedin interfaceSchema<V>
-
messageFullName
Description copied from interface:SchemaReturns the full name of the message tied to this schema. Allows custom schemas to provide a custom name other than typeClass().getName();- Specified by:
messageFullNamein interfaceSchema<V>
-
messageName
Description copied from interface:SchemaReturns the simple name of the message tied to this schema. Allows custom schemas to provide a custom name other than typeClass().getSimpleName();- Specified by:
messageNamein interfaceSchema<V>
-
typeClass
-
newMessage
Description copied from interface:SchemaCreates the message/object tied to this schema.- Specified by:
newMessagein interfaceSchema<V>
-
mergeFrom
-
writeWithNullTo
- Throws:
IOException
-
writeWithoutNullTo
- Throws:
IOException
-
writeTo
-