From 80652007b5dea1a4c2a9e86f8847c37feed73b26 Mon Sep 17 00:00:00 2001 From: Patrick Radtke Date: Mon, 21 Apr 2014 14:29:29 -0700 Subject: [PATCH] RelaxedDataBinder handling for untyped map Fixes gh-709 --- .../boot/bind/RelaxedDataBinder.java | 3 +++ .../boot/bind/RelaxedDataBinderTests.java | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedDataBinder.java b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedDataBinder.java index b9c7bb4d6c8..c793736ceb3 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedDataBinder.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedDataBinder.java @@ -229,6 +229,9 @@ public class RelaxedDataBinder extends DataBinder { return; } TypeDescriptor descriptor = parent.getMapValueTypeDescriptor(); + if (descriptor == null) { + descriptor = TypeDescriptor.valueOf(Object.class); + } if (!descriptor.isMap() && !descriptor.isCollection() && !descriptor.getType().equals(Object.class)) { return; diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java index 694f005b679..b0d376b8a4a 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java @@ -258,6 +258,13 @@ public class RelaxedDataBinderTests { assertEquals("123", target.getNested().get("value")); } + @Test + public void testBindNestedUntypedMap() throws Exception { + TargetWithNestedUntypedMap target = new TargetWithNestedUntypedMap(); + bind(target, "nested.foo: bar\n" + "nested.value: 123"); + assertEquals("123", target.getNested().get("value")); + } + @Test public void testBindNestedMapOfString() throws Exception { TargetWithNestedMapOfString target = new TargetWithNestedMapOfString(); @@ -503,6 +510,22 @@ public class RelaxedDataBinderTests { } } + + @SuppressWarnings("rawtypes") + public static class TargetWithNestedUntypedMap { + + private Map nested; + + public Map getNested() { + return this.nested; + } + + public void setNested(Map nested) { + this.nested = nested; + } + + } + public static class TargetWithNestedMapOfString {