1 package com.fasterxml.jackson.failing; 2 3 import java.util.Collections; 4 import java.util.Map; 5 6 import com.fasterxml.jackson.annotation.JsonUnwrapped; 7 import com.fasterxml.jackson.databind.BaseMapTest; 8 import com.fasterxml.jackson.databind.ObjectMapper; 9 10 // Tests for [#171] 11 public class TestUnwrappedMap171 extends BaseMapTest 12 { 13 static class MapUnwrap { 14 MapUnwrap()15 public MapUnwrap() { } MapUnwrap(String key, Object value)16 public MapUnwrap(String key, Object value) { 17 map = Collections.singletonMap(key, value); 18 } 19 20 @JsonUnwrapped(prefix="map.") 21 public Map<String, Object> map; 22 } 23 24 // // // Reuse mapper to keep tests bit faster 25 26 private final ObjectMapper MAPPER = new ObjectMapper(); 27 28 /* 29 /********************************************************** 30 /* Tests, serialization 31 /********************************************************** 32 */ 33 testMapUnwrapSerialize()34 public void testMapUnwrapSerialize() throws Exception 35 { 36 String json = MAPPER.writeValueAsString(new MapUnwrap("test", 6)); 37 assertEquals("{\"map.test\": 6}", json); 38 } 39 40 /* 41 /********************************************************** 42 /* Tests, deserialization 43 /********************************************************** 44 */ 45 testMapUnwrapDeserialize()46 public void testMapUnwrapDeserialize() throws Exception 47 { 48 MapUnwrap root = MAPPER.readValue("{\"map.test\": 6}", MapUnwrap.class); 49 50 assertEquals(1, root.map.size()); 51 assertEquals(6, ((Number)root.map.get("test")).intValue()); 52 } 53 } 54