|
| 1 | +package com.fasterxml.jackson.failing; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 4 | +import com.fasterxml.jackson.databind.*; |
| 5 | +import com.fasterxml.jackson.databind.introspect.AnnotatedMember; |
| 6 | +import com.fasterxml.jackson.databind.introspect.AnnotatedParameter; |
| 7 | +import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; |
| 8 | + |
| 9 | +public class CreatorWithNamingStrategy2008Test extends BaseMapTest |
| 10 | +{ |
| 11 | + @SuppressWarnings("serial") |
| 12 | + static class MyParamIntrospector extends JacksonAnnotationIntrospector |
| 13 | + { |
| 14 | + @Override |
| 15 | + public String findImplicitPropertyName(AnnotatedMember param) { |
| 16 | + if (param instanceof AnnotatedParameter) { |
| 17 | + AnnotatedParameter ap = (AnnotatedParameter) param; |
| 18 | + return "paramName"+ap.getIndex(); |
| 19 | + } |
| 20 | + return super.findImplicitPropertyName(param); |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + // wrt [https://github.com/FasterXML/jackson-modules-java8/issues/67] |
| 25 | + static class OneProperty { |
| 26 | + public String paramName0; |
| 27 | + |
| 28 | + @JsonCreator |
| 29 | + public OneProperty(String bogus) { |
| 30 | + paramName0 = "CTOR:"+bogus; |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + /* |
| 35 | + /********************************************************** |
| 36 | + /* Test methods |
| 37 | + /********************************************************** |
| 38 | + */ |
| 39 | + |
| 40 | + private final ObjectMapper MAPPER = objectMapper() |
| 41 | + .setAnnotationIntrospector(new MyParamIntrospector()) |
| 42 | + .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE) |
| 43 | + ; |
| 44 | + |
| 45 | + // Possibly [databind#2008], but originally |
| 46 | + // wrt [https://github.com/FasterXML/jackson-modules-java8/issues/67] |
| 47 | + public void testSnakeCaseWithOneArg() throws Exception |
| 48 | + { |
| 49 | + final String MSG = "1st"; |
| 50 | + OneProperty actual = MAPPER.readValue( |
| 51 | + "{\"first_property\":\""+MSG+"\"}", |
| 52 | + OneProperty.class); |
| 53 | + assertEquals("CTOR:"+MSG, actual.paramName0); |
| 54 | + } |
| 55 | +} |
0 commit comments