|
1 |
| -package com.fasterxml.jackson.databind.creators; |
| 1 | +package com.fasterxml.jackson.databind.deser.creators; |
| 2 | + |
| 3 | +import java.util.Map; |
2 | 4 |
|
3 | 5 | import com.fasterxml.jackson.annotation.*;
|
4 | 6 | import com.fasterxml.jackson.databind.*;
|
@@ -139,6 +141,16 @@ public static SingleArgWithImplicit from(XY v) {
|
139 | 141 | public XY getFoobar() { return _value; }
|
140 | 142 | }
|
141 | 143 |
|
| 144 | + // [databind#1631] |
| 145 | + static class SingleArg1631 { |
| 146 | + Object value; |
| 147 | + |
| 148 | + @JsonCreator // but no mode! |
| 149 | + public SingleArg1631(Object arg) { |
| 150 | + value = arg; |
| 151 | + } |
| 152 | + } |
| 153 | + |
142 | 154 | /*
|
143 | 155 | /**********************************************************
|
144 | 156 | /* Test methods
|
@@ -207,5 +219,25 @@ public void testSingleImplicitDelegating() throws Exception
|
207 | 219 | assertEquals(1, v.x);
|
208 | 220 | assertEquals(2, v.y);
|
209 | 221 | }
|
210 |
| -} |
211 | 222 |
|
| 223 | + // [databind#1631] |
| 224 | + public void testSingleArgAsPropertiesViaFeature() throws Exception |
| 225 | + { |
| 226 | + // First things first: should default to delegating, in absence of anything else: |
| 227 | + SingleArg1631 result = MAPPER.readValue(quote("zap"), SingleArg1631.class); |
| 228 | + assertEquals("zap", result.value); |
| 229 | + |
| 230 | + // and should bind to Map if given JSON Object (since nominal type Object) |
| 231 | + final String json = aposToQuotes("{'ctor':'ding'}"); |
| 232 | + result = MAPPER.readValue(json, SingleArg1631.class); |
| 233 | + assertTrue(result.value instanceof Map<?,?>); |
| 234 | + |
| 235 | + // But change of defaults should work wonders: |
| 236 | + final ObjectMapper mapper = new ObjectMapper(); |
| 237 | + mapper.enable(MapperFeature.CREATOR_MODE_DEFAULT_PROPERTIES); |
| 238 | + mapper.setAnnotationIntrospector(new MyParamIntrospector("ctor")); |
| 239 | + |
| 240 | + result = mapper.readValue(json, SingleArg1631.class); |
| 241 | + assertEquals("ding", result.value); |
| 242 | + } |
| 243 | +} |
0 commit comments