/** * Indicates whether the given {@code desiredFormat} is supported as a representation for this type. More * specifically, it will consult the serializer that returned this instance whether it has a converter to convert * the serialized object's data to the desired type * * @param desiredFormat the format in which the serialized object is desired * @param <T> the format in which the serialized object is desired * @return {@code true} if the format is supported, otherwise {@code false} */ public <T> boolean supportsFormat(Class<T> desiredFormat) { return serializer.getConverter().canConvert(serializedObject.getContentType(), desiredFormat); }
private RemoteExceptionDescription deserializeException(Serializer serializer) { return serializer.deserialize(new SimpleSerializedObject<>(serializedException, byte[].class, exceptionType, exceptionRevision)); }
/** * Returns the data contained in the serialized object in the given {@code desiredFormat}, if supported. If the * desired format is unsupported, an exception is thrown, depending on the serializer. * <p> * To verify whether a format is supported, use {@link #supportsFormat(Class)}. * * @param desiredFormat the format in which the data is desired * @param <T> the format in which the data is desired * @return the data in the desired format */ public <T> T readData(Class<T> desiredFormat) { return serializer.getConverter().convert(serializedObject, desiredFormat).getData(); }
private static void putDeadlineScope(JobDataMap jobData, ScopeDescriptor deadlineScope, Serializer serializer) { SerializedObject<byte[]> serializedDeadlineScope = serializer.serialize(deadlineScope, byte[].class); jobData.put(SERIALIZED_DEADLINE_SCOPE, serializedDeadlineScope.getData()); jobData.put(SERIALIZED_DEADLINE_SCOPE_CLASS_NAME, serializedDeadlineScope.getType().getName()); }
@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); }
private String getSagaTypeName(Class<?> sagaType) { return serializer.typeForClass(sagaType).getName(); }
@SuppressWarnings("unchecked") @Override public <S, T> T deserialize(SerializedObject<S> serializedObject) { if (SerializedType.emptyType().equals(serializedObject.getType())) { return null; } if (UnknownSerializedType.class.isAssignableFrom(classForType(serializedObject.getType()))) { return (T) new UnknownSerializedType(this, serializedObject); } return (T) doDeserialize(serializedObject, xStream); }
/** * 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 @SuppressWarnings("unchecked") public <D> SerializedObject<D> getData(Class<D> requiredType) { return serializer.getConverter().convert(data, requiredType); }
private static <S, T> Route calculateRoute(Class<S> sourceType, Class<T> targetType, Collection<ContentTypeConverter<?, ?>> candidates) { return new RouteCalculator(candidates).calculateRoute(sourceType, targetType); }
/** * Convert the given {@code source}, of type {@code sourceType} to the given {@code targetType}. * * @param <S> The type of data that needs to be converted * @param <T> The target type of the conversion * @param source The object to convert * @param sourceType The source type of the conversion * @param targetType The target type of the conversion * @return The converted object */ protected <S, T> T convert(S source, Class<S> sourceType, Class<T> targetType) { return getConverter().convert(source, sourceType, targetType); }
@Override public R getPayload() { if (serializedPayload == null) { return null; } return serializedPayload.getObject(); }
@Override public Class<R> getPayloadType() { if (serializedPayload == null) { return null; } return serializedPayload.getType(); }
/** * Returns the type that represents an empty message, of undefined type. The type of such message is "empty" and * always has a {@code null} revision. * * @return the type representing an empty message */ static SerializedType emptyType() { return SimpleSerializedType.emptyType(); }
@Override public Builder converter(Converter converter) { super.converter(converter); return this; }
/** * Initializes a SimpleSerializedObject using given {@code data} and a serialized type identified by given * {@code type} and {@code revision}. * * @param data The data of the serialized object * @param dataType The type of data * @param type The type identifying the serialized object * @param revision The revision of the serialized object */ public SimpleSerializedObject(T data, Class<T> dataType, String type, String revision) { this(data, dataType, new SimpleSerializedType(type, revision)); }
/** * Initializes a {@link GenericEventMessage} with given message as delegate and given {@code timestamp}. The * given message will be used supply the payload, metadata and identifier of the resulting event message. * * @param delegate the message that will be used used as delegate * @param timestamp the timestamp of the resulting event message */ protected GenericEventMessage(Message<T> delegate, Instant timestamp) { this(delegate, CachingSupplier.of(timestamp)); }
/** * Indicates whether the payload of this message has already been deserialized. * * @return {@code true} if the payload is deserialized, otherwise {@code false} */ public boolean isPayloadDeserialized() { return payload.isDeserialized(); }
@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); }
private Object deserializePayload(Serializer serializer) { return serializer.deserialize(new SimpleSerializedObject<>(serializedPayload, byte[].class, payloadType, payloadRevision)); }