cartridge-java icon indicating copy to clipboard operation
cartridge-java copied to clipboard

Incorrect implementation of the map converter

Open wey1and opened this issue 3 years ago • 0 comments

Test case:

    @Test
    public void test(){
        DefaultMessagePackMapper mapper = DefaultMessagePackMapperFactory.getInstance().defaultComplexTypesMapper();
        Map<Long, String> expected = new HashMap<>();
        expected.put((long) (Short.MAX_VALUE + 1), "test");
        expected.put((long) (Short.MAX_VALUE + 2), "test");

        Map<Long, String> actual = mapper.fromValue(mapper.toValue(expected));

        String s = expected.get((long) Short.MAX_VALUE + 1);
        String t = actual.get((long) Short.MAX_VALUE + 1);

        assertNotNull(s);
        assertNotNull(t); //fail at this assertion!!!
    }

This case shows that when a value in the range of Integer is inserted into the map, the Integer converter is taken from the converter stack, regardless of the specified generic class in the resulting variable. (The same thing happens with short and int, respectively)

This problem can be solved by rewriting the DefaultMapObjectConverter, specifically the toValue method. Perhaps through reflection.

wey1and avatar Aug 26 '21 18:08 wey1and