|
| 1 | +package com.fasterxml.jackson.failing; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonSubTypes; |
| 4 | +import com.fasterxml.jackson.annotation.JsonTypeInfo; |
| 5 | +import com.fasterxml.jackson.databind.BaseMapTest; |
| 6 | +import com.fasterxml.jackson.databind.MapperFeature; |
| 7 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 8 | +import java.io.IOException; |
| 9 | + |
| 10 | +public class JsonTypeInfoCaseInsensitive1983Test extends BaseMapTest { |
| 11 | + |
| 12 | + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "operation") |
| 13 | + @JsonSubTypes({ |
| 14 | + @JsonSubTypes.Type(value = Equal.class, name = "eq"), |
| 15 | + @JsonSubTypes.Type(value = NotEqual.class, name = "noteq"), |
| 16 | + }) |
| 17 | + static abstract class Filter { |
| 18 | + } |
| 19 | + |
| 20 | + static class Equal extends Filter { |
| 21 | + } |
| 22 | + |
| 23 | + static class NotEqual extends Filter { |
| 24 | + } |
| 25 | + |
| 26 | + public void testReadMixedCaseSubclass() throws IOException { |
| 27 | +// There is also "ACCEPT_CASE_INSENSITIVE_VALUES" feature. Is it more suitable here, or I should leave it as is? |
| 28 | + ObjectMapper mapper = objectMapper().enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); |
| 29 | + String serialised = "{\"operation\":\"NoTeQ\"}"; |
| 30 | + |
| 31 | + Filter result = mapper.readValue(serialised, Filter.class); |
| 32 | + |
| 33 | + assertEquals(NotEqual.class, result.getClass()); |
| 34 | + } |
| 35 | + |
| 36 | + public void testReadMixedCasePropertyName() throws IOException { |
| 37 | + ObjectMapper mapper = objectMapper().enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); |
| 38 | + String serialised = "{\"oPeRaTioN\":\"noteq\"}"; |
| 39 | + |
| 40 | + Filter result = mapper.readValue(serialised, Filter.class); |
| 41 | + |
| 42 | + assertEquals(NotEqual.class, result.getClass()); |
| 43 | + } |
| 44 | +} |
0 commit comments