Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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; }
- @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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement