Skip to content

Commit 9aad873

Browse files
committed
Start work merging #2241
1 parent e7b3baf commit 9aad873

File tree

3 files changed

+71
-8
lines changed

3 files changed

+71
-8
lines changed

src/main/java/com/fasterxml/jackson/databind/PropertyNamingStrategy.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public class PropertyNamingStrategy // NOTE: was abstract until 2.7
7676
*/
7777
public static final PropertyNamingStrategy KEBAB_CASE = new KebabCaseStrategy();
7878

79+
/**
80+
* Naming convention widely used as configuration properties name, where words are in
81+
* lower-case letters, separated by dots.
82+
* See {@link LowerDotCaseStrategy} for details.
83+
*
84+
* @since 2.10
85+
*/
86+
public static final PropertyNamingStrategy LOWER_DOT_CASE = new LowerDotCaseStrategy();
87+
7988
/*
8089
/**********************************************************
8190
/* API
@@ -396,7 +405,26 @@ public String translate(String input)
396405
return result.toString();
397406
}
398407
}
399-
408+
409+
/**
410+
* Naming strategy similar to {@link KebabCaseStrategy}, but instead of hyphens
411+
* as separators, uses dots. Naming convention widely used as configuration properties name.
412+
*
413+
* @since 2.10
414+
*/
415+
public static class LowerDotCaseStrategy extends PropertyNamingStrategyBase {
416+
/*
417+
@Override
418+
public String translate(String input){
419+
return translateLowerCaseWithSeparator(input, '.');
420+
}
421+
*/
422+
@Override
423+
public String translate(String input) {
424+
return input.toLowerCase();
425+
}
426+
}
427+
400428
/*
401429
/**********************************************************
402430
/* Deprecated variants, aliases

src/test/java/com/fasterxml/jackson/databind/BaseMapTest.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,13 @@ protected static ObjectMapper newObjectMapper() {
233233
return new ObjectMapper();
234234
}
235235

236-
// @since 2.10s
236+
// @since 2.10
237237
protected static JsonMapper.Builder objectMapperBuilder() {
238-
/* 27-Aug-2018, tatu: Now this is weird -- with Java 7, we seem to need
239-
* explicit type parameters, but not with Java 8.
240-
* This need renders builder-approach pretty much useless for Java 7,
241-
* which is ok for 3.x (where baseline is Java 8), but potentially
242-
* problematic for 2.10. Oh well.
243-
*/
238+
return JsonMapper.builder();
239+
}
240+
241+
// @since 2.10
242+
protected static JsonMapper.Builder jsonMapperBuilder() {
244243
return JsonMapper.builder();
245244
}
246245

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

+36
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,42 @@ public void testSimpleKebabCase() throws Exception
337337
assertEquals("Billy", result.firstName);
338338
}
339339

340+
/*
341+
/**********************************************************
342+
/* Test methods for LOWER_DOT_CASE
343+
/**********************************************************
344+
*/
345+
346+
/*
347+
public void testLowerCaseWithDotsStrategyStandAlone()
348+
{
349+
assertEquals("some.value",
350+
PropertyNamingStrategy.LOWER_DOT_CASE.nameForField(null, null, "someValue"));
351+
assertEquals("some.value",
352+
PropertyNamingStrategy.LOWER_DOT_CASE.nameForField(null, null, "SomeValue"));
353+
assertEquals("url",
354+
PropertyNamingStrategy.LOWER_DOT_CASE.nameForField(null, null, "URL"));
355+
assertEquals("url.stuff",
356+
PropertyNamingStrategy.LOWER_DOT_CASE.nameForField(null, null, "URLStuff"));
357+
assertEquals("some.url.stuff",
358+
PropertyNamingStrategy.LOWER_DOT_CASE.nameForField(null, null, "SomeURLStuff"));
359+
}
360+
361+
public void testSimpleLowerCaseWithDots() throws Exception
362+
{
363+
final ObjectMapper m = jsonMapperBuilder()
364+
.propertyNamingStrategy(PropertyNamingStrategy.LOWER_DOT_CASE)
365+
.build();
366+
367+
final FirstNameBean input = new FirstNameBean("Bob");
368+
assertEquals(aposToQuotes("{'first.name':'Bob'}"), m.writeValueAsString(input));
369+
370+
FirstNameBean result = m.readValue(aposToQuotes("{'first.name':'Billy'}"),
371+
FirstNameBean.class);
372+
assertEquals("Billy", result.firstName);
373+
}
374+
*/
375+
340376
/*
341377
/**********************************************************
342378
/* Test methods, other

0 commit comments

Comments
 (0)