Skip to content

Commit

Permalink
Properly deserialize lists with @SnsNotificationMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
frjonsen committed Nov 24, 2024
1 parent 6151537 commit 25e7f5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ private Object fromGenericMessages(List<GenericMessage<?>> messages, Class<?> ta
Type resolvedType = getResolvedType(targetClass, conversionHint);
Class<?> resolvedClazz = ResolvableType.forType(resolvedType).resolve();

return messages.stream().map(message -> fromGenericMessage(message, resolvedClazz, resolvedType)).toList();
Object hint = targetClass.isAssignableFrom(List.class) &&
conversionHint instanceof MethodParameter mp ? mp.nested() : conversionHint;

return messages.stream().map(message -> fromGenericMessage(message, resolvedClazz, hint)).toList();
}

private Object fromGenericMessage(GenericMessage<?> message, Class<?> targetClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ static class ResolvesPojoWithNotificationAnnotationListener {

@SqsListener(queueNames = RESOLVES_POJO_FROM_NOTIFICATION_MESSAGE_QUEUE_NAME, id = "resolves-pojo-with-notification-message", factory = "defaultSqsListenerContainerFactory")
void listen(@SnsNotificationMessage MyEnvelope<MyPojo> myPojo) {
Assert.notNull((myPojo).data.firstField, "Received null message");
assertThat(myPojo.getData().getFirstField()).isEqualTo("pojoNotificationMessage");
logger.debug("Received message {} from queue {}", myPojo,
RESOLVES_POJO_FROM_NOTIFICATION_MESSAGE_QUEUE_NAME);
latchContainer.resolvesPojoNotificationMessageLatch.countDown();
Expand All @@ -286,6 +286,10 @@ void listen(@SnsNotificationMessage List<MyEnvelope<MyPojo>> myPojos) {
Assert.notEmpty(myPojos, "Received empty messages");
logger.debug("Received messages {} from queue {}", myPojos,
RESOLVES_POJO_FROM_NOTIFICATION_MESSAGE_LIST_QUEUE_NAME);

for (MyEnvelope<MyPojo> myPojo : myPojos) {
assertThat(myPojo.getData().getFirstField()).isEqualTo("pojoNotificationMessage");
}
latchContainer.resolvesPojoNotificationMessageListLatch.countDown();
}
}
Expand Down

0 comments on commit 25e7f5b

Please sign in to comment.