Arsnael commented on code in PR #2991:
URL: https://github.com/apache/james-project/pull/2991#discussion_r3044366454
##########
event-bus/api/src/main/java/org/apache/james/events/EventSerializersAggregator.java:
##########
@@ -37,34 +36,38 @@ public EventSerializersAggregator(Set<EventSerializer>
allEventSerializers) {
}
@Override
- public Optional<String> toJson(Event event) {
+ public SerializationResult toJson(Event event) {
return allEventSerializers.stream()
.map(eventSerializer -> eventSerializer.toJson(event))
- .flatMap(Optional::stream)
- .findFirst();
+ .filter(SerializationResult::isSuccess)
+ .findFirst()
+ .orElse(new SerializationResult.Failure("Could not serialize
event: " + event));
}
@Override
- public Optional<Event> asEvent(String serialized) {
+ public DeserializationResult asEvent(String serialized) {
return allEventSerializers.stream()
.map(eventSerializer -> eventSerializer.asEvent(serialized))
- .flatMap(Optional::stream)
- .findFirst();
+ .filter(DeserializationResult::isSuccess)
+ .findFirst()
+ .orElse(new DeserializationResult.Failure("Could not deserialize
event: " + serialized));
}
@Override
- public Optional<String> toJson(Collection<Event> events) {
+ public SerializationResult toJson(Collection<Event> events) {
return allEventSerializers.stream()
.map(eventSerializer -> eventSerializer.toJson(events))
- .flatMap(Optional::stream)
- .findFirst();
+ .filter(SerializationResult::isSuccess)
+ .findFirst()
+ .orElse(new SerializationResult.Failure("Could not serialize
events: " + events));
}
@Override
- public Optional<List<Event>> asEvents(String serialized) {
+ public List<DeserializationResult> asEvents(String serialized) {
return allEventSerializers.stream()
.map(eventSerializer -> eventSerializer.asEvents(serialized))
- .flatMap(Optional::stream)
- .findFirst();
+ .filter(results ->
results.stream().anyMatch(DeserializationResult::isSuccess))
Review Comment:
Should I generify the DeserializationResult for having two types of success,
one for event, one for list of events?
Afraid of complexifying things but if not I dont see how to avoid the stream
in the stream here...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]