Skip to content

Commit

Permalink
Improve unit testing to reproduce issue #428
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 28, 2014
1 parent 907c375 commit 1ab4fda
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import java.util.*;

import com.fasterxml.jackson.annotation.*;

import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.fasterxml.jackson.databind.annotation.*;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
Expand Down Expand Up @@ -149,11 +149,12 @@ public String translate(String propertyName) {

static class RenamedCollectionBean
{
@JsonDeserialize
private List<String> THEvalues = Collections.emptyList();
// @JsonDeserialize
@JsonProperty
private List<String> theValues = Collections.emptyList();

// intentionally odd name, to be renamed by naming strategy
public List<String> getTheVALUEs() { return THEvalues; }
public List<String> getTheValues() { return theValues; }
}

// [Issue#45]: Support @JsonNaming
Expand Down Expand Up @@ -230,15 +231,16 @@ public void testWithGetterAsSetter() throws Exception
}

// For [JACKSON-687]
public void testJson() throws Exception
public void testLowerCase() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(new LcStrategy());
// mapper.disable(DeserializationConfig.DeserializationFeature.USE_GETTERS_AS_SETTERS);
RenamedCollectionBean foo = mapper.readValue("{\"thevalues\":[\"a\"]}", RenamedCollectionBean.class);
assertNotNull(foo.getTheVALUEs());
assertEquals(1, foo.getTheVALUEs().size());
assertEquals("a", foo.getTheVALUEs().get(0));
RenamedCollectionBean result = mapper.readValue("{\"thevalues\":[\"a\"]}",
RenamedCollectionBean.class);
assertNotNull(result.getTheValues());
assertEquals(1, result.getTheValues().size());
assertEquals("a", result.getTheValues().get(0));
}

// @JsonNaming / [Issue#45]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public OtherNonStandardNames(String Results, String _User, String ___, String $U
this.$User = $User;
}
}

static class Bean428 {
@JsonProperty("fooBar")
public String whatever() {return "";}
}

/*
/**********************************************************
Expand Down Expand Up @@ -241,10 +246,9 @@ public void testLowerCaseUnchangedNames() throws Exception
* PASCAL_CASE_TO_CAMEL_CASE was added in Jackson 2.1.0,
* as per [JACKSON-63].
*/
@Test
public void testPascalCaseStandAlone()
{
String translatedJavaName = PropertyNamingStrategy.PASCAL_CASE_TO_CAMEL_CASE.nameForField
String translatedJavaName = PropertyNamingStrategy.PASCAL_CASE_TO_CAMEL_CASE.nameForField
(null, null, "userName");
assertEquals("UserName", translatedJavaName);

Expand All @@ -259,4 +263,19 @@ public void testPascalCaseStandAlone()
(null, null, "x");
assertEquals("X", translatedJavaName);
}

/**
* [Issue#428]
*/
public void testIssue428PascalWithOverrides() throws Exception {

String json = new ObjectMapper()
.setPropertyNamingStrategy(PropertyNamingStrategy.PASCAL_CASE_TO_CAMEL_CASE)
.writeValueAsString(new Bean428());

if (!json.contains(quote("fooBar"))) {
fail("Should use name 'fooBar', does not: "+json);
}
}
}

0 comments on commit 1ab4fda

Please sign in to comment.