@Test void testExceptionSerialization() { Throwable expected = new Throwable("oops"); ResultMessage<?> resultMessage = asResultMessage(expected); JacksonSerializer jacksonSerializer = JacksonSerializer.builder().build(); SerializedObject<String> serializedObject = resultMessage.serializeExceptionResult(jacksonSerializer, String.class); RemoteExceptionDescription actual = jacksonSerializer.deserialize(serializedObject); assertEquals("java.lang.Throwable: oops", actual.getDescriptions().get(0)); }
@SuppressWarnings("unchecked") public static <T> ResultMessage<T> asResultMessage(Object result) { if (result instanceof ResultMessage) { return (ResultMessage<T>) result; } else if (result instanceof Message) { Message<?> resultMessage = (Message<?>) result; return (ResultMessage<T>) new GenericResultMessage<>(resultMessage); } return new GenericResultMessage<>((T) result); }
GenericResultMessage extends MessageDecorator<R> implements ResultMessage<R> { @SuppressWarnings("unchecked") public static <T> ResultMessage<T> asResultMessage(Object result) { if (result instanceof ResultMessage) { return (ResultMessage<T>) result; } else if (result instanceof Message) { Message<?> resultMessage = (Message<?>) result; return (ResultMessage<T>) new GenericResultMessage<>(resultMessage); } return new GenericResultMessage<>((T) result); } }
GenericResultMessage extends MessageDecorator<R> implements ResultMessage<R> { @SuppressWarnings("unchecked") public static <T> ResultMessage<T> asResultMessage(Object result) { if (result instanceof ResultMessage) { return (ResultMessage<T>) result; } else if (result instanceof Message) { Message<?> resultMessage = (Message<?>) result; return (ResultMessage<T>) new GenericResultMessage<>(resultMessage); } return new GenericResultMessage<>((T) result); } GenericResultMessage(R result);  GenericResultMessage(Throwable exception);  GenericResultMessage(R result, Map<String, ?> metaData);  GenericResultMessage(Throwable exception, Map<String, ?> metaData);  GenericResultMessage(Message<R> delegate);  GenericResultMessage(Message<R> delegate, Throwable exception); }
GenericResultMessage extends MessageDecorator<R> implements ResultMessage<R> { @SuppressWarnings("unchecked") public static <T> ResultMessage<T> asResultMessage(Object result) { if (result instanceof ResultMessage) { return (ResultMessage<T>) result; } else if (result instanceof Message) { Message<?> resultMessage = (Message<?>) result; return (ResultMessage<T>) new GenericResultMessage<>(resultMessage); } return new GenericResultMessage<>((T) result); } GenericResultMessage(R result);  GenericResultMessage(Throwable exception);  GenericResultMessage(R result, Map<String, ?> metaData);  GenericResultMessage(Throwable exception, Map<String, ?> metaData);  GenericResultMessage(Message<R> delegate);  GenericResultMessage(Message<R> delegate, Throwable exception); @SuppressWarnings("unchecked") static ResultMessage<T> asResultMessage(Object result); static ResultMessage<T> asResultMessage(Throwable exception); @Override boolean isExceptional(); @Override Optional<Throwable> optionalExceptionResult(); @Override SerializedObject<S> serializePayload(Serializer serializer, Class<S> expectedRepresentation); @Override GenericResultMessage<R> withMetaData(Map<String, ?> metaData); @Override GenericResultMessage<R> andMetaData(Map<String, ?> metaData); @SuppressWarnings("unchecked") @Override R getPayload(); }
GenericResultMessage extends MessageDecorator<R> implements ResultMessage<R> { @SuppressWarnings("unchecked") public static <T> ResultMessage<T> asResultMessage(Object result) { if (result instanceof ResultMessage) { return (ResultMessage<T>) result; } else if (result instanceof Message) { Message<?> resultMessage = (Message<?>) result; return (ResultMessage<T>) new GenericResultMessage<>(resultMessage); } return new GenericResultMessage<>((T) result); } GenericResultMessage(R result);  GenericResultMessage(Throwable exception);  GenericResultMessage(R result, Map<String, ?> metaData);  GenericResultMessage(Throwable exception, Map<String, ?> metaData);  GenericResultMessage(Message<R> delegate);  GenericResultMessage(Message<R> delegate, Throwable exception); @SuppressWarnings("unchecked") static ResultMessage<T> asResultMessage(Object result); static ResultMessage<T> asResultMessage(Throwable exception); @Override boolean isExceptional(); @Override Optional<Throwable> optionalExceptionResult(); @Override SerializedObject<S> serializePayload(Serializer serializer, Class<S> expectedRepresentation); @Override GenericResultMessage<R> withMetaData(Map<String, ?> metaData); @Override GenericResultMessage<R> andMetaData(Map<String, ?> metaData); @SuppressWarnings("unchecked") @Override R getPayload();  }