添加到RedisAggregationRepository时的序列化

kfgdxczn  于 8个月前  发布在  Redis
关注(0)|答案(1)|浏览(90)

我们在一个项目上使用Apache Camel,当我们聚合一些交换时,我们想使用RedisAggregationRepository,但我在序列化主体时遇到了麻烦,主体是包含enum的记录。所以我的记录看起来像这样(简化):

@Builder
@Jacksonized
public record NotificationData(
...
        @NotNull
        Type type,
...
)  {

    public enum Type {
        INTERNAL, EXTERNAL
    }
}

我有一个使用RedisAggregationRepository的路由,NotificationData是交换的主体。当添加到Redis时,会发生以下异常:

Exception caught: java.lang.IllegalArgumentException: java.io.IOException: java.lang.UnsupportedOperationException: can't get field offset on a record class: private final NotificationData$Type NotificationData.type
    at org.redisson.command.CommandAsyncService.encodeMapValue(CommandAsyncService.java:732)
    at org.redisson.RedissonObject.encodeMapValue(RedissonObject.java:310)
    at org.redisson.RedissonMap.putOperationAsync(RedissonMap.java:1372)
    at org.redisson.RedissonMap.putAsync(RedissonMap.java:1358)
    at org.redisson.RedissonMap.put(RedissonMap.java:664)
    at org.apache.camel.component.redis.processor.aggregate.RedisAggregationRepository.add(RedisAggregationRepository.java:134)
...

Caused by: java.lang.UnsupportedOperationException: can't get field offset on a record class: private final NotificationData$Type NotificationData.type
    at jdk.unsupported/sun.misc.Unsafe.objectFieldOffset(Unsafe.java:648)
    at org.jboss.marshalling.reflect.SerializableField.<init>(SerializableField.java:58)
    at org.jboss.marshalling.reflect.SerializableClass.getSerializableFields(SerializableClass.java:121)
    at org.jboss.marshalling.reflect.SerializableClass.<init>(SerializableClass.java:88)
    at org.jboss.marshalling.reflect.SerializableClassRegistry$1.computeValue(SerializableClassRegistry.java:62)
    at org.jboss.marshalling.reflect.SerializableClassRegistry$1.computeValue(SerializableClassRegistry.java:59)
    at java.base/java.lang.ClassValue.getFromHashMap(ClassValue.java:228)
    at java.base/java.lang.ClassValue.getFromBackup(ClassValue.java:210)
    at java.base/java.lang.ClassValue.get(ClassValue.java:116)
    at org.jboss.marshalling.reflect.SerializableClassRegistry.lookup(SerializableClassRegistry.java:83)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:180)
    at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
    at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
    at org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
    at org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
    at java.base/java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    at java.base/java.util.CollSer.writeObject(ImmutableCollections.java:1465)
    at org.jboss.marshalling.reflect.JDKSpecific$SerMethods.callWriteObject(JDKSpecific.java:89)
    at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:193)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1089)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:268)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1143)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1101)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:268)
    at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:58)
    at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:111)
    at org.redisson.codec.MarshallingCodec.lambda$new$1(MarshallingCodec.java:161)
    ... 170 more
Caused by: an exception which occurred:
    in field org.apache.camel.support.DefaultExchangeHolder.inBody
    in object org.apache.camel.support.DefaultExchangeHolder@901212
    in object org.apache.camel.support.DefaultExchangeHolder@901212

是我做错了什么,还是这不受支持?

fykwrbwg

fykwrbwg1#

我认为这个问题与jboss-marshalling serializer问题有关。在下面的问题中,jboss-marshalling不支持java记录。因此,他们建议使用另一个序列化器,如Kryo。

你可以通过参考下面的redisson官方文档选择另一个序列化器。

谢谢

相关问题