Skip to content

Commit 441f20c

Browse files
committed
Merge branch '2.6'
Conflicts: src/test/java/com/fasterxml/jackson/databind/introspect/TestNamingStrategyStd.java
2 parents 321562a + 6aaa38b commit 441f20c

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

release-notes/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ INCOMPATIBILITIES:
5151
(reported by Antibrumm@github)
5252
#989: Deserialization from "{}" to java.lang.Object causes "out of END_OBJECT token" error
5353
(reported by Ievgen P)
54+
- Fix a minor problem with `@JsonNaming` not recognizing default value
5455

5556
2.6.3 (12-Oct-2015)
5657

src/main/java/com/fasterxml/jackson/databind/annotation/JsonNaming.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
/**
88
* Annotation that can be used to indicate a {@link PropertyNamingStrategy}
99
* to use for annotated class. Overrides the global (default) strategy.
10+
* Note that if the {@link #value} property is omitted, its default value
11+
* means "use default naming" (that is, no alternate naming method is used).
12+
* This can be used as an override with mix-ins.
1013
*
1114
* @since 2.1
1215
*/

src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,11 @@ private PropertyNamingStrategy _findNamingStrategy()
10081008
+namingDef.getClass().getName()+"; expected type PropertyNamingStrategy or Class<PropertyNamingStrategy> instead");
10091009
}
10101010
Class<?> namingClass = (Class<?>)namingDef;
1011+
// 09-Nov-2015, tatu: Need to consider pseudo-value of STD, which means "use default"
1012+
if (namingClass == PropertyNamingStrategy.class) {
1013+
return null;
1014+
}
1015+
10111016
if (!PropertyNamingStrategy.class.isAssignableFrom(namingClass)) {
10121017
throw new IllegalStateException("AnnotationIntrospector returned Class "
10131018
+namingClass.getName()+"; expected Class<PropertyNamingStrategy>");

src/test/java/com/fasterxml/jackson/databind/introspect/TestNamingStrategyStd.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ public static class ClassWithObjectNodeField {
9797
public ObjectNode json;
9898
}
9999

100+
static class ExplicitBean {
101+
@JsonProperty("firstName")
102+
String userFirstName = "Peter";
103+
@JsonProperty("lastName")
104+
String userLastName = "Venkman";
105+
@JsonProperty
106+
String userAge = "35";
107+
}
108+
109+
@JsonNaming()
110+
static class DefaultNaming {
111+
public int someValue = 3;
112+
}
113+
100114
/*
101115
/**********************************************************
102116
/* Set up
@@ -318,15 +332,6 @@ public void testNamingWithObjectNode() throws Exception
318332
assertEquals("bing", result.json.path("baz").asText());
319333
}
320334

321-
static class ExplicitBean {
322-
@JsonProperty("firstName")
323-
String userFirstName = "Peter";
324-
@JsonProperty("lastName")
325-
String userLastName = "Venkman";
326-
@JsonProperty
327-
String userAge = "35";
328-
}
329-
330335
public void testExplicitRename() throws Exception {
331336
ObjectMapper m = new ObjectMapper();
332337
m.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
@@ -352,6 +357,13 @@ public void testExplicitRename() throws Exception {
352357
assertEquals("Egon", bean.userFirstName);
353358
assertEquals("Spengler", bean.userLastName);
354359
assertEquals("32", bean.userAge);
360+
}
355361

362+
// Also verify that "no naming strategy" should be ok
363+
public void testExplicitNoNaming() throws Exception
364+
{
365+
ObjectMapper mapper = objectMapper();
366+
String json = mapper.writeValueAsString(new DefaultNaming());
367+
assertEquals(aposToQuotes("{'someValue':3}"), json);
356368
}
357369
}

0 commit comments

Comments
 (0)