Kaynağa Gözat

Test Jackson HashMap in Whitelist

Issue: gh-4889
Rob Winch 7 yıl önce
ebeveyn
işleme
803cdcf01e

+ 9 - 0
core/src/test/java/org/springframework/security/jackson2/SecurityJackson2ModulesTests.java

@@ -26,6 +26,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import java.lang.annotation.*;
+import java.util.HashMap;
 
 import static org.assertj.core.api.Assertions.*;
 
@@ -84,6 +85,14 @@ public class SecurityJackson2ModulesTests {
 		assertThat(mapper.readValue(content, Object.class)).isInstanceOf(NotWhitelisted.class);
 	}
 
+	@Test
+	public void readValueWhenHashMapThenReadsAsSpecificType() throws Exception {
+		mapper.addMixIn(NotWhitelisted.class, NotWhitelistedMixin.class);
+		String content = "{\"@class\":\"java.util.HashMap\"}";
+
+		assertThat(mapper.readValue(content, Object.class)).isInstanceOf(HashMap.class);
+	}
+
 	@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE })
 	@Retention(RetentionPolicy.RUNTIME)
 	@Documented