Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jackson2RedisSerializer cannot deserialize ObjectId fields [DATAREDIS-392] #967

Closed
spring-projects-issues opened this issue Apr 4, 2015 · 1 comment
Assignees
Labels
in: core Issues in core support type: bug A general bug

Comments

@spring-projects-issues
Copy link

Prashant Deva opened DATAREDIS-392 and commented

This code:

public static void main(String[] args) throws IOException
    {

        GlobalMetricID txnID = new GlobalMetricID();
        txnID.appId = new ObjectId("530a4bf1fe0e15115a197577");
        txnID.metricId = 1;
        txnID.metricName = "hello";

        Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(GlobalMetricID.class);
        byte[] bytes = serializer.serialize(txnID);
        String s1 = new String(bytes);
        System.out.println(s1);

        Object deserialize = serializer.deserialize(bytes);
        System.out.println(deserialize);
    }

results in this

{"appId":{"time":1393183729000,"date":1393183729000,"timestamp":1393183729,"machine":-32631535,"timeSecond":1393183729,"new":false,"inc":1511617911},"metricName":"hello","metricId":1,"name":"hello"}
Exception in thread "main" org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized field "time" (class org.bson.types.ObjectId), not marked as ignorable (0 known properties: ])
 at [Source: [B@4387b79e; line: 1, column: 31] (through reference chain: com.dripstat.metricprocessor.mongo.GlobalMetricID["appId"]->org.bson.types.ObjectId["time"]); nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "time" (class org.bson.types.ObjectId), not marked as ignorable (0 known properties: ])
 at [Source: [B@4387b79e; line: 1, column: 31] (through reference chain: com.dripstat.metricprocessor.mongo.GlobalMetricID["appId"]->org.bson.types.ObjectId["time"])
	at org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer.deserialize(Jackson2JsonRedisSerializer.java:73)
	at com.dripstat.metricprocessor.metric.caches.MetricIdCache.main(MetricIdCache.java:120)
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "time" (class org.bson.types.ObjectId), not marked as ignorable (0 known properties: ])
 at [Source: [B@4387b79e; line: 1, column: 31] (through reference chain: com.dripstat.metricprocessor.mongo.GlobalMetricID["appId"]->org.bson.types.ObjectId["time"])
	at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:51)
	at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:731)
	at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:915)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1298)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1276)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:243)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:118)
	at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:538)
	at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:106)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:238)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:118)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3051)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2255)
	at org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer.deserialize(Jackson2JsonRedisSerializer.java:71)
	... 1 more

This means anyone trying to cache mongodb documents using redis will face this exception.
This is a critical exception since the error is thrown during deserialization, so users will fill up their cache with data that cannot be serialized


Affects: 1.5 GA (Fowler)

Issue Links:

Referenced from: pull request #145

Backported to: 1.5.3 (Fowler SR3)

1 votes, 3 watchers

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

Looks generally good to me. Just a few minor questions on the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants