Skip to content

Commit 80eea15

Browse files
committed
Ignore type in the MessageJacksonDeserializer
The `GenericJackson2JsonRedisSerializer` now resolves the target type before calling `ObjectMapper.readValue()` causing a `ClassCast` in the `StdNodeBasedDeserializer.deserializeWithType()` * Override `MessageJacksonDeserializer.deserializeWithType()` with delegating to the plain `deserialize()` ignoring the `TypeDeserializer` Related to spring-projects/spring-data-redis#2322
1 parent ccf41d1 commit 80eea15

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

spring-integration-core/src/main/java/org/springframework/integration/support/json/MessageJacksonDeserializer.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,11 +24,13 @@
2424
import org.springframework.messaging.Message;
2525
import org.springframework.util.Assert;
2626

27+
import com.fasterxml.jackson.core.JsonParser;
2728
import com.fasterxml.jackson.databind.DeserializationContext;
2829
import com.fasterxml.jackson.databind.JavaType;
2930
import com.fasterxml.jackson.databind.JsonNode;
3031
import com.fasterxml.jackson.databind.ObjectMapper;
3132
import com.fasterxml.jackson.databind.deser.std.StdNodeBasedDeserializer;
33+
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
3234
import com.fasterxml.jackson.databind.type.TypeFactory;
3335

3436
/**
@@ -66,6 +68,13 @@ protected ObjectMapper getMapper() {
6668
return this.mapper;
6769
}
6870

71+
@Override
72+
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer td)
73+
throws IOException {
74+
75+
return super.deserialize(jp, ctxt);
76+
}
77+
6978
@Override
7079
public T convert(JsonNode root, DeserializationContext ctxt) throws IOException {
7180
Map<String, Object> headers = this.mapper.readValue(root.get("headers").traverse(),

spring-integration-redis/src/test/java/org/springframework/integration/redis/store/RedisChannelMessageStoreTests.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import org.springframework.beans.factory.annotation.Autowired;
3030
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
31-
import org.springframework.data.redis.serializer.JacksonObjectWriter;
3231
import org.springframework.integration.IntegrationMessageHeaderAccessor;
3332
import org.springframework.integration.channel.NullChannel;
3433
import org.springframework.integration.history.MessageHistory;
@@ -185,10 +184,7 @@ void testPriority() {
185184
void testJsonSerialization() {
186185
RedisChannelMessageStore store = new RedisChannelMessageStore(RedisContainerTest.connectionFactory());
187186
ObjectMapper mapper = JacksonJsonUtils.messagingAwareMapper();
188-
GenericJackson2JsonRedisSerializer serializer =
189-
new GenericJackson2JsonRedisSerializer(mapper,
190-
(mapper1, source, type) -> mapper1.readValue(source, Object.class),
191-
JacksonObjectWriter.create());
187+
GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer(mapper);
192188
store.setValueSerializer(serializer);
193189

194190
Message<?> genericMessage = new GenericMessage<>(new Date());

0 commit comments

Comments
 (0)