chibenwa commented on code in PR #2991:
URL: https://github.com/apache/james-project/pull/2991#discussion_r3050540866
##########
event-bus/api/src/main/java/org/apache/james/events/EventSerializersAggregator.java:
##########
@@ -37,70 +36,38 @@ public EventSerializersAggregator(Set<EventSerializer>
allEventSerializers) {
}
@Override
- public String toJson(Event event) {
+ public SerializationResult toJson(Event event) {
return allEventSerializers.stream()
- .map(eventSerializer -> serialize(event, eventSerializer))
- .flatMap(Optional::stream)
+ .map(eventSerializer -> eventSerializer.toJson(event))
+ .filter(SerializationResult::isSuccess)
.findFirst()
- .orElseThrow(() -> new RuntimeException("Could not serialize
event: " + event));
+ .orElse(new SerializationResult.Failure("Could not serialize
event: " + event));
}
@Override
- public Event asEvent(String serialized) {
+ public DeserializationResult asEvent(String serialized) {
return allEventSerializers.stream()
- .map(eventSerializer -> deserialize(serialized, eventSerializer))
- .flatMap(Optional::stream)
+ .map(eventSerializer -> eventSerializer.asEvent(serialized))
+ .filter(DeserializationResult::isSuccess)
.findFirst()
- .orElseThrow(() -> new RuntimeException("Could not deserialize
event: " + serialized));
+ .orElse(new DeserializationResult.Failure("Could not deserialize
event: " + serialized));
}
@Override
- public String toJson(Collection<Event> events) {
+ public SerializationResult toJson(Collection<Event> events) {
return allEventSerializers.stream()
- .map(eventSerializer -> serialize(events, eventSerializer))
- .flatMap(Optional::stream)
+ .map(eventSerializer -> eventSerializer.toJson(events))
+ .filter(SerializationResult::isSuccess)
.findFirst()
- .orElseThrow(() -> new RuntimeException("Could not serialize
event: " + events));
+ .orElse(new SerializationResult.Failure("Could not serialize
events: " + events));
}
@Override
- public List<Event> asEvents(String serialized) {
+ public List<DeserializationResult> asEvents(String serialized) {
Review Comment:
```suggestion
public ListDeserializationResult asEvents(String serialized) {
```
--
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]