-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
541a3ca
commit 3d4e4ec
Showing
2 changed files
with
69 additions
and
5 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
56 changes: 56 additions & 0 deletions
56
src/test/java/com/fasterxml/jackson/failing/ImplicitNameMatch792Test.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,56 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedMember; | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter; | ||
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; | ||
|
||
public class ImplicitNameMatch792Test extends BaseMapTest | ||
{ | ||
// Simple introspector that gives generated "ctorN" names for constructor | ||
// parameters | ||
static class ConstructorNameAI extends JacksonAnnotationIntrospector | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public String findImplicitPropertyName(AnnotatedMember member) { | ||
if (member instanceof AnnotatedParameter) { | ||
return String.format("ctor%d", ((AnnotatedParameter) member).getIndex()); | ||
} | ||
return super.findImplicitPropertyName(member); | ||
} | ||
} | ||
|
||
@JsonPropertyOrder({ "first" ,"second", "other" }) | ||
static class Issue792Bean | ||
{ | ||
// Should match implicit name of the first constructor parameter, | ||
// and thus get renamed as "first" for serialization purposes | ||
String ctor0; | ||
|
||
public Issue792Bean(@JsonProperty("first") String a, | ||
@JsonProperty("second") String b) { | ||
ctor0 = a; | ||
// ignore second arg | ||
} | ||
|
||
public int getOther() { return 3; } | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Test methods | ||
/********************************************************** | ||
*/ | ||
|
||
public void testBindingOfImplicitNames() throws Exception | ||
{ | ||
ObjectMapper m = new ObjectMapper(); | ||
m.setAnnotationIntrospector(new ConstructorNameAI()); | ||
String json = m.writeValueAsString(new Issue792Bean("a", "b")); | ||
assertEquals(aposToQuotes("{'first':'a','other':3}"), json); | ||
} | ||
} |