@@ -168,8 +168,10 @@ protected FirstNameBean() { }
168
168
// [databind#1026]
169
169
{"usId" , "us_id" },
170
170
{"uId" , "u_id" },
171
+ // [databind#2267]
172
+ {"xCoordinate" , "x_coordinate" },
171
173
});
172
-
174
+
173
175
private ObjectMapper _lcWithUndescoreMapper ;
174
176
175
177
@ Override
@@ -363,30 +365,30 @@ public void testNamingWithObjectNode() throws Exception
363
365
364
366
public void testExplicitRename () throws Exception
365
367
{
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 );
390
392
}
391
393
392
394
// Also verify that "no naming strategy" should be ok
0 commit comments