Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

org.springframework.data.mapping.MappingException, can not convert map to object using hashmapper

$
0
0

when converting map read from redis to my entity object,it throws such an exception: org.springframework.data.mapping.MappingException: Unexpected token (VALUE_STRING), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class java.util.List at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: edu.why.core.model.IDInfo["fixParts"])
here is my code:

@org.junit.jupiter.api.Test
    public void test8() {
        IDInfo info=new IDInfo();
        info.setIndexPosition(1);
        info.setLength(4);
        info.setNextIndex(2);
        info.setStartIndex(100);
        info.setStep(1);
        List<FixedPart> list=new ArrayList<>();
        list.add(new StringFixedPart("ss"));
        list.add(new DateTimeFixedPart("y"));
        info.setFixParts(list);
        redisTemplate.opsForHash().putAll("map",mapper.toHash(info));
        Map map=redisTemplate.opsForHash().entries("map");
        IDInfo result=(IDInfo) mapper.fromHash(map);//this line throws the exception
    }

this is my mapper:

    @Bean
    public HashMapper hashMapper(){
        return new DecoratingStringHashMapper(new Jackson2HashMapper(false));
    }

this is my entity:

public class IDInfo {
    private long startIndex;      //the first index
    private int indexPosition;   //the position of the index
    private int length;             //the length of the index
    private long nextIndex;       //the next index to be returned
    private int step;               //the amount each increase by
    private List<FixedPart> fixParts; //the content of fixpart
    //omit setter and getter 
}

It work well when converting object to Map,but throw an exception when converting Map back to Objcet.Why?


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>