-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #67 (or, fix via databind, but add release notes, tests)
- Loading branch information
1 parent
ff76427
commit b8ccc50
Showing
6 changed files
with
135 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
parameter-names/src/test/java/com/fasterxml/jackson/module/paramnames/ModuleTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.fasterxml.jackson.module.paramnames; | ||
|
||
import java.util.Arrays; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class ModuleTestBase | ||
{ | ||
protected static ObjectMapper newMapper() { | ||
return new ObjectMapper() | ||
.registerModule(new ParameterNamesModule()); | ||
} | ||
|
||
protected String quote(String value) { | ||
return "\"" + value + "\""; | ||
} | ||
|
||
protected String aposToQuotes(String json) { | ||
return json.replace("'", "\""); | ||
} | ||
|
||
protected void verifyException(Throwable e, String... matches) | ||
{ | ||
String msg = e.getMessage(); | ||
String lmsg = (msg == null) ? "" : msg.toLowerCase(); | ||
for (String match : matches) { | ||
String lmatch = match.toLowerCase(); | ||
if (lmsg.indexOf(lmatch) >= 0) { | ||
return; | ||
} | ||
} | ||
throw new Error("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\""); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ter-names/src/test/java/com/fasterxml/jackson/module/paramnames/NamingStrategy67Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.fasterxml.jackson.module.paramnames; | ||
|
||
import static org.assertj.core.api.BDDAssertions.then; | ||
|
||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
|
||
public class NamingStrategy67Test extends ModuleTestBase | ||
{ | ||
static class ClassWithOneProperty { | ||
public final String firstProperty; | ||
|
||
@JsonCreator | ||
// @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) | ||
public ClassWithOneProperty(String firstProperty) { | ||
this.firstProperty = "CTOR:"+firstProperty; | ||
} | ||
} | ||
static class ClassWithTwoProperties { | ||
public final int a; | ||
public final int b; | ||
|
||
private ClassWithTwoProperties(@JsonProperty("a") int a, @JsonProperty("b") int b) { | ||
this.a = a+1; | ||
this.b = b+1; | ||
} | ||
} | ||
|
||
@Test | ||
public void testSnakeCaseNaming() throws Exception | ||
{ | ||
ObjectMapper mapper = newMapper() | ||
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE) | ||
; | ||
final String MSG = "1st"; | ||
ClassWithOneProperty actual = mapper.readValue( | ||
// "\""+MSG+"\"", | ||
"{\"first_property\":\""+MSG+"\"}", | ||
// "{\"firstProperty\":\""+MSG+"\"}", | ||
ClassWithOneProperty.class); | ||
then(actual).isEqualToComparingFieldByField(new ClassWithOneProperty(MSG)); | ||
} | ||
|
||
@Test | ||
public void testPrivateConstructorWithPropertyAnnotations() throws Exception | ||
{ | ||
ObjectMapper mapper = newMapper() | ||
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); | ||
ClassWithTwoProperties actual = mapper.readValue("{\"a\":1, \"b\": 2}", | ||
ClassWithTwoProperties.class); | ||
|
||
then(actual).isEqualToComparingFieldByField(new ClassWithTwoProperties(1, 2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters