Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

Show that deserializing Map<String, Object> breaks :( #12

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ public JavaType resolveAbstractType(DeserializationConfig config, JavaType type)
/* We won't be handling any container types (Collections, Maps and arrays),
* Throwables or enums.
*/
if (type.isContainerType() || type.isPrimitive() || type.isEnumType() || type.isThrowable()) {
if (type.isContainerType() || type.isPrimitive() || type.isEnumType() || type.isThrowable() ||
type.getRawClass() == Number.class)
{
return null;
}
Class<?> cls = type.getRawClass();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.fasterxml.jackson.module.mrbean;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class TestMapStringObjectDeserialization
extends BaseTest
{

/**
* Test simple Map deserialization works.
*/
public void testMapWithMrbean() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new MrBeanModule());

runTest(mapper);
}

/**
* Test simple Map deserialization works.
*/
public void testMapWithoutMrbean() throws Exception
{
ObjectMapper mapper = new ObjectMapper();

runTest(mapper);
}

void runTest(ObjectMapper mapper) throws IOException, JsonParseException, JsonMappingException
{
Map<String, Object> map = mapper.readValue("{\"test\":3 }", new TypeReference<Map<String, Object>>() {});
assertEquals(Collections.singletonMap("test", 3), map);
}
}