Skip to content

Commit 6aaa38b

Browse files
committed
Fix a minor problem with @JsonNaming not recognizing default value ("no naming")
1 parent d5a25f4 commit 6aaa38b

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

release-notes/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Project: jackson-databind
1010
(reported by Antibrumm@github)
1111
#989: Deserialization from "{}" to java.lang.Object causes "out of END_OBJECT token" error
1212
(reported by Ievgen P)
13+
- Fix a minor problem with `@JsonNaming` not recognizing default value
1314

1415
2.6.3 (12-Oct-2015)
1516

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
@@ -1007,6 +1007,11 @@ private PropertyNamingStrategy _findNamingStrategy()
10071007
+namingDef.getClass().getName()+"; expected type PropertyNamingStrategy or Class<PropertyNamingStrategy> instead");
10081008
}
10091009
Class<?> namingClass = (Class<?>)namingDef;
1010+
// 09-Nov-2015, tatu: Need to consider pseudo-value of STD, which means "use default"
1011+
if (namingClass == PropertyNamingStrategy.class) {
1012+
return null;
1013+
}
1014+
10101015
if (!PropertyNamingStrategy.class.isAssignableFrom(namingClass)) {
10111016
throw new IllegalStateException("AnnotationIntrospector returned Class "
10121017
+namingClass.getName()+"; expected Class<PropertyNamingStrategy>");

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ public static class ClassWithObjectNodeField {
9696
public ObjectNode json;
9797
}
9898

99+
static class ExplicitBean {
100+
@JsonProperty("firstName")
101+
String userFirstName = "Peter";
102+
@JsonProperty("lastName")
103+
String userLastName = "Venkman";
104+
@JsonProperty
105+
String userAge = "35";
106+
}
107+
108+
@JsonNaming()
109+
static class DefaultNaming {
110+
public int someValue = 3;
111+
}
112+
99113
/*
100114
/**********************************************************
101115
/* Set up
@@ -316,4 +330,12 @@ public void testNamingWithObjectNode() throws Exception
316330
assertEquals(2, result.json.size());
317331
assertEquals("bing", result.json.path("baz").asText());
318332
}
333+
334+
// Also verify that "no naming strategy" should be ok
335+
public void testExplicitNoNaming() throws Exception
336+
{
337+
ObjectMapper mapper = objectMapper();
338+
String json = mapper.writeValueAsString(new DefaultNaming());
339+
assertEquals(aposToQuotes("{'someValue':3}"), json);
340+
}
319341
}

0 commit comments

Comments
 (0)