/** * De-serializes the object and returns the result. * * @return the deserialized object */ public T getObject() { if (!isDeserialized()) { deserializedObject = serializer.deserialize(serializedObject.get()); } return deserializedObject; }
@Override public <T> SerializedObject<T> serialize(Object object, Class<T> expectedRepresentation) { return delegate.serialize(object, expectedRepresentation); }
@SuppressWarnings("unchecked") public <T> SerializedObject<T> serializePayload(Serializer serializer, Class<T> expectedRepresentation) { synchronized (payloadGuard) { SerializedObject existingForm = serializedPayload.get(serializer); if (existingForm == null) { SerializedObject<T> serialized = serializer.serialize(message.getPayload(), expectedRepresentation); if (message.getPayload() == null) { // make sure the payload type is maintained serialized = new SimpleSerializedObject<>(serialized.getData(), serialized.getContentType(), serializer.typeForClass(message.getPayloadType())); } serializedPayload.put(serializer, serialized); return serialized; } else { return serializer.getConverter().convert(existingForm, expectedRepresentation); } } }
@SuppressWarnings("unchecked") public <T> SerializedObject<T> serializeMetaData(Serializer serializer, Class<T> expectedRepresentation) { synchronized (metaDataGuard) { SerializedObject existingForm = serializedMetaData.get(serializer); if (existingForm == null) { SerializedObject<T> serialized = serializer.serialize(message.getMetaData(), expectedRepresentation); serializedMetaData.put(serializer, serialized); return serialized; } else { return serializer.getConverter().convert(existingForm, expectedRepresentation); } } } }
/** * Constructs a new SagaEntry for the given {@code saga}. The given saga must be serializable. The provided * saga is not modified by this operation. * * @param identifier The identifier of the saga * @param saga The saga to store * @param associationValues The associations of the saga * @param serializer The serialization mechanism to convert the Saga to a byte stream */ public SagaEntry(String identifier, T saga, Set<AssociationValue> associationValues, Serializer serializer) { this.sagaId = identifier; SerializedObject<byte[]> serialized = serializer.serialize(saga, byte[].class); this.serializedSaga = serialized.getData(); this.sagaType = serializer.typeForClass(saga.getClass()).getName(); this.saga = saga; this.associationValues = new HashSet<>(associationValues); }
@Override public SerializedType typeForClass(Class type) { return delegate.typeForClass(type); }
@Override public Class classForType(SerializedType type) { return delegate.classForType(type); }
@Override public Converter getConverter() { return delegate.getConverter(); } }
@Override public <T> boolean canSerializeTo(Class<T> expectedRepresentation) { return delegate.canSerializeTo(expectedRepresentation); }
@SuppressWarnings("unchecked") @Override public <R> SerializedObject<R> serializePayload(Serializer serializer, Class<R> expectedRepresentation) { if (serializer.equals(payload.getSerializer())) { return serializer.getConverter().convert(payload.getSerializedObject(), expectedRepresentation); } return serializer.serialize(payload.getObject(), expectedRepresentation); }
/** * Constructs a new SagaEntry for the given {@code saga}. The given saga must be serializable. The provided * saga is not modified by this operation. * * @param identifier The identifier of the saga * @param saga The saga to store * @param associationValues The associations of the saga * @param serializer The serialization mechanism to convert the Saga to a byte stream */ public SagaEntry(String identifier, T saga, Set<AssociationValue> associationValues, Serializer serializer) { this.sagaId = identifier; SerializedObject<byte[]> serialized = serializer.serialize(saga, byte[].class); this.serializedSaga = serialized.getData(); this.sagaType = serializer.typeForClass(saga.getClass()).getName(); this.saga = saga; this.associationValues = new HashSet<>(associationValues); }
private String getSagaTypeName(Class<?> sagaType) { return serializer.typeForClass(sagaType).getName(); }
@Override public boolean test(DomainEventData<?> snapshot) { final SerializedType payloadType = snapshot.getPayload().getType(); final String payloadRevision = payloadType.getRevision(); final String aggregateRevision; try { aggregateRevision = resolver.revisionOf(serializer.classForType(payloadType)); } catch (Exception e) { // Unable to resolve a revision, ignoring this snapshot return false; } return Objects.equals(payloadRevision, aggregateRevision); } }
@Override @SuppressWarnings("unchecked") public <D> SerializedObject<D> getData(Class<D> requiredType) { return serializer.getConverter().convert(data, requiredType); }
@Override public <T> boolean canSerializeTo(Class<T> expectedRepresentation) { return delegate.canSerializeTo(expectedRepresentation); }
/** * Returns the token, deserializing it with given {@code serializer} * * @param serializer The serialize to deserialize the token with * @return the deserialized token stored in this entry */ public TrackingToken getToken(Serializer serializer) { return token == null ? null : serializer.deserialize(getSerializedToken()); }
/** * Serialize the payload of this message to the {@code expectedRepresentation} using given {@code serializer}. This * method <em>should</em> return the same SerializedObject instance when invoked multiple times using the same * serializer. * * @param serializer The serializer to serialize payload with * @param expectedRepresentation The type of data to serialize to * @param <R> The type of the serialized data * @return a SerializedObject containing the serialized representation of the message's payload */ default <R> SerializedObject<R> serializePayload(Serializer serializer, Class<R> expectedRepresentation) { return serializer.serialize(getPayload(), expectedRepresentation); }
@SuppressWarnings("unchecked") @Override public <R> SerializedObject<R> serializeMetaData(Serializer serializer, Class<R> expectedRepresentation) { if (serializer.equals(metaData.getSerializer())) { return serializer.getConverter().convert(metaData.getSerializedObject(), expectedRepresentation); } return serializer.serialize(metaData.getObject(), expectedRepresentation); }
/** * Utility method that serializes the payload of the given {@code message} using given {@code serializer} * and {@code expectedRepresentation}. This method will verify if the {@code eventMessage} is {@link * SerializationAware}. * * @param message The message containing the payload to serialize * @param serializer The serializer to serialize the payload with * @param expectedRepresentation The data type to serialize to * @param <T> The data type to serialize to * @return a Serialized Object containing the serialized for of the message's payload */ public static <T> SerializedObject<T> serializePayload(Message<?> message, Serializer serializer, Class<T> expectedRepresentation) { if (message instanceof SerializationAware) { return ((SerializationAware) message).serializePayload(serializer, expectedRepresentation); } SerializedObject<T> serializedObject = serializer.serialize(message.getPayload(), expectedRepresentation); if (message.getPayload() == null) { // make sure the payload type is maintained return new SimpleSerializedObject<>(serializedObject.getData(), serializedObject.getContentType(), serializer.typeForClass(message.getPayloadType())); } return serializedObject; }
@SuppressWarnings("unchecked") public <T> SerializedObject<T> serializePayload(Serializer serializer, Class<T> expectedRepresentation) { synchronized (payloadGuard) { SerializedObject existingForm = serializedPayload.get(serializer); if (existingForm == null) { SerializedObject<T> serialized = serializer.serialize(message.getPayload(), expectedRepresentation); if (message.getPayload() == null) { // make sure the payload type is maintained serialized = new SimpleSerializedObject<>(serialized.getData(), serialized.getContentType(), serializer.typeForClass(message.getPayloadType())); } serializedPayload.put(serializer, serialized); return serialized; } else { return serializer.getConverter().convert(existingForm, expectedRepresentation); } } }