Package org.axonframework.serialization
Class SerializedMessage<T>
java.lang.Object
org.axonframework.messaging.AbstractMessage<T>
org.axonframework.serialization.SerializedMessage<T>
- All Implemented Interfaces:
Serializable,Message<T>
A message containing serialized payload data and metadata. A SerializedMessage will deserialize the payload or
metadata on demand when
getPayload() or getMetaData() is called.
The SerializedMessage guarantees that the payload and metadata will not be deserialized more than once. Messages of this type will not be serialized more than once by the same serializer.
- Author:
- Rene de Waele
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSerializedMessage(String identifier, LazyDeserializingObject<T> payload, LazyDeserializingObject<MetaData> metaData) Initializes aSerializedMessagewith givenidentifierfrom the given lazily deserializing payload and metadata.SerializedMessage(String identifier, SerializedObject<?> serializedPayload, SerializedObject<?> serializedMetaData, Serializer serializer) Initializes aSerializedMessagewith givenidentifierfrom the given serialized payload and metadata. -
Method Summary
Modifier and TypeMethodDescriptionandMetaData(Map<String, ?> metaData) Returns a copy of this Message with it MetaData merged with the givenmetaData.Returns the meta data for this message.Returns the payload of this message.Returns the type of the payload.booleanIndicates whether the metaData of this message has already been deserialized.booleanIndicates whether the payload of this message has already been deserialized.<R> SerializedObject<R> serializeMetaData(Serializer serializer, Class<R> expectedRepresentation) Serialize the meta data of this message to theexpectedRepresentationusing givenserializer.<R> SerializedObject<R> serializePayload(Serializer serializer, Class<R> expectedRepresentation) Serialize the payload of this message to theexpectedRepresentationusing givenserializer.withMetaData(Map<String, ?> metaData) Returns a copy of this Message with the givenmetaData.protected SerializedMessage<T> withMetaData(MetaData metaData) Returns a new message instance with the same payload and properties as this message but givenmetaData.protected ObjectJava Serialization API Method that provides a replacement to serialize, as the fields contained in this instance are not serializable themselves.Methods inherited from class org.axonframework.messaging.AbstractMessage
getIdentifier
-
Constructor Details
-
SerializedMessage
public SerializedMessage(String identifier, SerializedObject<?> serializedPayload, SerializedObject<?> serializedMetaData, Serializer serializer) Initializes aSerializedMessagewith givenidentifierfrom the given serialized payload and metadata. The givenserializerwill be used to deserialize the data.- Parameters:
identifier- the message identifierserializedPayload- the serialized message payloadserializedMetaData- the serialized message metadataserializer- the serializer required when the data needs to be deserialized
-
SerializedMessage
public SerializedMessage(String identifier, LazyDeserializingObject<T> payload, LazyDeserializingObject<MetaData> metaData) Initializes aSerializedMessagewith givenidentifierfrom the given lazily deserializing payload and metadata.- Parameters:
identifier- the message identifierpayload- serialized payload that can be deserialized on demand and never more than oncemetaData- serialized metadata that can be deserialized on demand and never more than once
-
-
Method Details
-
getPayload
Description copied from interface:MessageReturns the payload of this message. The payload is the application-specific information.- Returns:
- the payload of this message
-
getMetaData
Description copied from interface:MessageReturns the meta data for this message. This meta data is a collection of key-value pairs, where the key is a String, and the value is a serializable object.- Returns:
- the meta data for this message
-
getPayloadType
Description copied from interface:MessageReturns the type of the payload. Is semantically equal togetPayload().getClass(), but allows implementations to optimize by using lazy loading or deserialization.- Returns:
- the type of payload.
-
withMetaData
Description copied from class:AbstractMessageReturns a new message instance with the same payload and properties as this message but givenmetaData.- Specified by:
withMetaDatain classAbstractMessage<T>- Parameters:
metaData- The metadata in the new message- Returns:
- a copy of this instance with given metadata
-
withMetaData
Description copied from interface:MessageReturns a copy of this Message with the givenmetaData. The payload remains unchanged. While the implementation returned may be different than the implementation ofthis, implementations must take special care in returning the same type of Message (e.g. EventMessage, DomainEventMessage) to prevent errors further downstream.- Specified by:
withMetaDatain interfaceMessage<T>- Overrides:
withMetaDatain classAbstractMessage<T>- Parameters:
metaData- The new MetaData for the Message- Returns:
- a copy of this message with the given MetaData
-
andMetaData
Description copied from interface:MessageReturns a copy of this Message with it MetaData merged with the givenmetaData. The payload remains unchanged.- Specified by:
andMetaDatain interfaceMessage<T>- Overrides:
andMetaDatain classAbstractMessage<T>- Parameters:
metaData- The MetaData to merge with- Returns:
- a copy of this message with the given MetaData
-
serializePayload
public <R> SerializedObject<R> serializePayload(Serializer serializer, Class<R> expectedRepresentation) Description copied from interface:MessageSerialize the payload of this message to theexpectedRepresentationusing givenserializer. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.- Type Parameters:
R- The type of the serialized data- Parameters:
serializer- The serializer to serialize payload withexpectedRepresentation- The type of data to serialize to- Returns:
- a SerializedObject containing the serialized representation of the message's payload
-
serializeMetaData
public <R> SerializedObject<R> serializeMetaData(Serializer serializer, Class<R> expectedRepresentation) Description copied from interface:MessageSerialize the meta data of this message to theexpectedRepresentationusing givenserializer. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.- Type Parameters:
R- The type of the serialized data- Parameters:
serializer- The serializer to serialize meta data withexpectedRepresentation- The type of data to serialize to- Returns:
- a SerializedObject containing the serialized representation of the message's meta data
-
isPayloadDeserialized
public boolean isPayloadDeserialized()Indicates whether the payload of this message has already been deserialized.- Returns:
trueif the payload is deserialized, otherwisefalse
-
isMetaDataDeserialized
public boolean isMetaDataDeserialized()Indicates whether the metaData of this message has already been deserialized.- Returns:
trueif the metaData is deserialized, otherwisefalse
-
writeReplace
Java Serialization API Method that provides a replacement to serialize, as the fields contained in this instance are not serializable themselves.- Returns:
- the GenericMessage to use as a replacement when serializing
-