You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by gmh <go...@gmail.com> on 2014/12/12 16:33:47 UTC

LinkedHashMap vs HashMap for Camel redis hmset operation

Hi,
I have a json that needs to be converted into a map.
I used Jackson as  dataformat and then gson 

<unmarshal ref="gson"/>

I noticed instead of hashmap I get linkedHashMap in the exchange

  BodyType            java.util.LinkedHashMap
  Body                {op=i, type=zones, objectId=548b083fb90a1072097cdeed,
id=Zone-cbs, Zone-cbs={createdOn=2014-11-24T10:13:21.444Z, modifiedOn=null,
attributes=[{name=Crib 1, value=Inventory}, {name=Access, value=Level1}],
zoneId=Zone-cbs}}

I am using the map for inserting into redis hshmap (hmset)

I have exceptions later on that complains about 

java.lang.ClassCastException: java.util.ArrayList cannot be cast to
java.lang.String
        at
org.springframework.data.redis.serializer.StringRedisSerializer.serialize(StringRedisSerializer.java:32)
        at
org.springframework.data.redis.core.AbstractOperations.rawHashValue(AbstractOperations.java:145)
        at
org.springframework.data.redis.core.DefaultHashOperations.putAll(DefaultHashOperations.java:124)
        at
org.apache.camel.component.redis.RedisClient.hmset(RedisClient.java:45)

I know in the Camel redis hmset code it is expecting java.util.Map.

see

    public void hmset(String key, Map<String, Object> param) {
        redisTemplate.opsForHash().putAll(key, param);
    }

Does it make a difference if it getting linkHashMap instead of Map?
How do I make sure I get java.util.Map object back?
Gordon



--
View this message in context: http://camel.465427.n5.nabble.com/LinkedHashMap-vs-HashMap-for-Camel-redis-hmset-operation-tp5760637.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: LinkedHashMap vs HashMap for Camel redis hmset operation

Posted by scottdawson <sc...@gmail.com>.
Gordon,
LinkedHashMap is a class that implements the java.util.Map interface, so,
you are getting a Map back. Since Map is an interface you will always get an
instance of some class that implements Map so it makes sense that the
unmarshal operation is returning a LinkedHashMap.

Regards,
Scott



--
View this message in context: http://camel.465427.n5.nabble.com/LinkedHashMap-vs-HashMap-for-Camel-redis-hmset-operation-tp5760637p5760653.html
Sent from the Camel - Users mailing list archive at Nabble.com.