Skip to content

Commit 3e65248

Browse files
committed
Try to reproduce #2267
1 parent c18df09 commit 3e65248

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

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

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ protected FirstNameBean() { }
168168
// [databind#1026]
169169
{"usId", "us_id" },
170170
{"uId", "u_id" },
171+
// [databind#2267]
172+
{"xCoordinate", "x_coordinate" },
171173
});
172-
174+
173175
private ObjectMapper _lcWithUndescoreMapper;
174176

175177
@Override
@@ -363,30 +365,30 @@ public void testNamingWithObjectNode() throws Exception
363365

364366
public void testExplicitRename() throws Exception
365367
{
366-
ObjectMapper m = new ObjectMapper();
367-
m.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
368-
m.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
369-
// by default, renaming will not take place on explicitly named fields
370-
assertEquals(aposToQuotes("{'firstName':'Peter','lastName':'Venkman','user_age':'35'}"),
371-
m.writeValueAsString(new ExplicitBean()));
372-
373-
m = new ObjectMapper();
374-
m.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
375-
m.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
376-
m.enable(MapperFeature.ALLOW_EXPLICIT_PROPERTY_RENAMING);
377-
// w/ feature enabled, ALL property names should get re-written
378-
assertEquals(aposToQuotes("{'first_name':'Peter','last_name':'Venkman','user_age':'35'}"),
379-
m.writeValueAsString(new ExplicitBean()));
380-
381-
// test deserialization as well
382-
ExplicitBean bean =
383-
m.readValue(aposToQuotes("{'first_name':'Egon','last_name':'Spengler','user_age':'32'}"),
384-
ExplicitBean.class);
385-
386-
assertNotNull(bean);
387-
assertEquals("Egon", bean.userFirstName);
388-
assertEquals("Spengler", bean.userLastName);
389-
assertEquals("32", bean.userAge);
368+
ObjectMapper m = new ObjectMapper();
369+
m.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
370+
m.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
371+
// by default, renaming will not take place on explicitly named fields
372+
assertEquals(aposToQuotes("{'firstName':'Peter','lastName':'Venkman','user_age':'35'}"),
373+
m.writeValueAsString(new ExplicitBean()));
374+
375+
m = new ObjectMapper();
376+
m.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
377+
m.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
378+
m.enable(MapperFeature.ALLOW_EXPLICIT_PROPERTY_RENAMING);
379+
// w/ feature enabled, ALL property names should get re-written
380+
assertEquals(aposToQuotes("{'first_name':'Peter','last_name':'Venkman','user_age':'35'}"),
381+
m.writeValueAsString(new ExplicitBean()));
382+
383+
// test deserialization as well
384+
ExplicitBean bean =
385+
m.readValue(aposToQuotes("{'first_name':'Egon','last_name':'Spengler','user_age':'32'}"),
386+
ExplicitBean.class);
387+
388+
assertNotNull(bean);
389+
assertEquals("Egon", bean.userFirstName);
390+
assertEquals("Spengler", bean.userLastName);
391+
assertEquals("32", bean.userAge);
390392
}
391393

392394
// Also verify that "no naming strategy" should be ok

0 commit comments

Comments
 (0)