Skip to content

Commit

Permalink
Add a test to show #792
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 13, 2015
1 parent 541a3ca commit 3d4e4ec
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public boolean hasCreatorAnnotation(Annotated a) {
return (a instanceof AnnotatedConstructor);
}
}

static class ValProperty
{
private final String prop‿;
Expand All @@ -69,7 +69,6 @@ public ValProperty(String prop) {
}
}


static class ValWithBeanProperty
{
private final String prop‿;
Expand All @@ -81,7 +80,6 @@ public ValWithBeanProperty(String prop) {
}
}


static class VarProperty
{
private String prop‿;
Expand All @@ -93,7 +91,6 @@ public VarProperty(String prop) {
}
}


static class VarWithBeanProperty
{
private String prop‿;
Expand All @@ -119,14 +116,19 @@ static class GetterSetterProperty
// getProp/setProp pairs.
}

/*
/**********************************************************
/* Test methods
/**********************************************************
*/

public void testValProperty() throws Exception
{
ObjectMapper m = manglingMapper();

assertEquals("{\"prop\":\"val\"}", m.writeValueAsString(new ValProperty("val")));
}


public void testValWithBeanProperty() throws Exception
{
ObjectMapper m = manglingMapper();
Expand Down Expand Up @@ -164,6 +166,12 @@ public void testGetterSetterProperty() throws Exception
assertEquals("read", result.prop());
}

/*
/**********************************************************
/* Helper methods
/**********************************************************
*/

private ObjectMapper manglingMapper()
{
ObjectMapper m = new ObjectMapper();
Expand Down
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);
}
}

0 comments on commit 3d4e4ec

Please sign in to comment.