Last active
November 30, 2015 04:30
-
-
Save snarayanank2/bae98cc72c3f2669481e to your computer and use it in GitHub Desktop.
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
import java.io.IOException; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import com.fasterxml.jackson.databind.PropertyNamingStrategy; | |
import com.fasterxml.jackson.datatype.joda.JodaModule; | |
public class TestCamelCase { | |
final static Logger logger = LoggerFactory.getLogger(TestBindAnnotations.class); | |
private ObjectMapper om; | |
@Before | |
public void before() { | |
om = new ObjectMapper(); | |
om.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); | |
om.registerModule(new JodaModule()); | |
} | |
class T1 { | |
public String uId; | |
public T1() {} | |
public T1(String uId) { this.uId = uId; } | |
public String toString() { | |
return "T1 [uId=" + uId + "]"; | |
} | |
} | |
@Test | |
public void testCaseNoGetter() throws IOException { | |
T1 x = new T1("hello"); | |
String json = om.writeValueAsString(x); | |
logger.info("json = " + json); | |
Assert.assertEquals("{\"u_id\":\"hello\"}", json); | |
} | |
class T2 { | |
private String uId; | |
public T2() {} | |
public T2(String uId) { this.uId = uId; } | |
public String getUId() { return uId; } | |
@Override | |
public String toString() { | |
return "T2 [uId=" + uId + "]"; | |
} | |
} | |
@Test | |
public void testCaseGetter() throws IOException { | |
T2 x = new T2("hello"); | |
String json = om.writeValueAsString(x); | |
logger.info("json = " + json); | |
Assert.assertEquals("{\"u_id\":\"hello\"}", json); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment