-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Labels
Description
Hi, It looks like that it's impossible right now to deserialize a JSON as vavr map tree, because only top level elements are deserialized as javaslang collections, deeper levels are java containers:
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import javaslang.collection.List;
import javaslang.collection.Map;
import javaslang.jackson.datatype.JavaslangModule;
import org.junit.Test;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
public class VavrJacksonTest {
private static final String JSON = "[\n" +
" {\n" +
" \"field1\": \"val1\",\n" +
" \"complexField\": {\n" +
" \"subField1\": \"subValue1\",\n" +
" \"subField2\": \"subValue2\"\n" +
" }\n" +
" }\n" +
"]";
@Test
public void nested_maps_should_be_javaslang_maps() throws IOException {
List<Map<String, Object>> listOfMapTrees = new ObjectMapper()
.registerModule(new JavaslangModule())
.readValue(JSON, new TypeReference<List<Map<String, Object>>>() {});
assertThat(listOfMapTrees.get().apply("complexField")).isInstanceOf(Map.class);
//Expecting:
// <{"subField1"="subValue1", "subField2"="subValue2"}>
//to be an instance of:
// <javaslang.collection.Map>
//but was instance of:
// <java.util.LinkedHashMap>
}
}bduisenov, czterocyty, chakriboos and yarulan