/** * Upcast the serialized payload of the event (leaving other aspects of the event the same). * * @param outputType The output type of the event after upcasting * @param expectedRepresentationType The type of the serialized payload required by the upcast function * @param upcastFunction The upcast function for the event's payload * @param <T> The expected payload type before and after upcasting * @return The intermediate representation of the event after upcasting */ default <T> IntermediateEventRepresentation upcastPayload(SerializedType outputType, Class<T> expectedRepresentationType, Function<T, T> upcastFunction) { return upcast(outputType, expectedRepresentationType, upcastFunction, Function.identity()); }
/** * Upcast the serialized payload of the event (leaving other aspects of the event the same). * * @param outputType The output type of the event after upcasting * @param expectedRepresentationType The type of the serialized payload required by the upcast function * @param upcastFunction The upcast function for the event's payload * @param <T> The expected payload type before and after upcasting * @return The intermediate representation of the event after upcasting */ default <T> IntermediateEventRepresentation upcastPayload(SerializedType outputType, Class<T> expectedRepresentationType, Function<T, T> upcastFunction) { return upcast(outputType, expectedRepresentationType, upcastFunction, Function.identity()); }
/** * Upcast the serialized payload of the event (leaving other aspects of the event the same). * * @param outputType The output type of the event after upcasting * @param expectedRepresentationType The type of the serialized payload required by the upcast function * @param upcastFunction The upcast function for the event's payload * @param <T> The expected payload type before and after upcasting * @return The intermediate representation of the event after upcasting */ default <T> IntermediateEventRepresentation upcastPayload(SerializedType outputType, Class<T> expectedRepresentationType, Function<T, T> upcastFunction) { return upcast(outputType, expectedRepresentationType, upcastFunction, Function.identity()); }
private static Stream<IntermediateEventRepresentation> upcastAndDeserialize( Stream<? extends EventData<?>> eventEntryStream, Serializer serializer, EventUpcaster upcasterChain, boolean skipUnknownTypes, Function<EventData<?>, IntermediateEventRepresentation> entryConverter) { Stream<IntermediateEventRepresentation> upcastResult = upcasterChain.upcast(eventEntryStream.map(entryConverter)); if (skipUnknownTypes) { upcastResult = upcastResult.map(ir -> { try { serializer.classForType(ir.getType()); return ir; } catch (UnknownSerializedTypeException e) { return ir.upcast(SerializedType.emptyType(), byte[].class, u -> EMPTY_BYTES, Function.identity()); } }); } return upcastResult; } }