Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import java.io.IOException;
  2.  
  3. import org.junit.Assert;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8.  
  9. import com.fasterxml.jackson.databind.ObjectMapper;
  10. import com.fasterxml.jackson.databind.PropertyNamingStrategy;
  11. import com.fasterxml.jackson.datatype.joda.JodaModule;
  12.  
  13.  
  14. public class TestCamelCase {
  15. final static Logger logger = LoggerFactory.getLogger(TestBindAnnotations.class);
  16. private ObjectMapper om;
  17.  
  18. @Before
  19. public void before() {
  20. om = new ObjectMapper();
  21. om.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
  22. om.registerModule(new JodaModule());
  23. }
  24.  
  25. class T1 {
  26. public String uId;
  27. public T1() {}
  28. public T1(String uId) { this.uId = uId; }
  29. public String toString() {
  30. return "T1 [uId=" + uId + "]";
  31. }
  32. }
  33.  
  34. @Test
  35. public void testCaseNoGetter() throws IOException {
  36. T1 x = new T1("hello");
  37. String json = om.writeValueAsString(x);
  38. logger.info("json = " + json);
  39. Assert.assertEquals("{\"u_id\":\"hello\"}", json);
  40. }
  41.  
  42. class T2 {
  43. private String uId;
  44. public T2() {}
  45. public T2(String uId) { this.uId = uId; }
  46. @Override
  47. public String toString() {
  48. return "T2 [uId=" + uId + "]";
  49. }
  50. }
  51.  
  52. @Test
  53. public void testCaseGetter() throws IOException {
  54. T2 x = new T2("hello");
  55. String json = om.writeValueAsString(x);
  56. logger.info("json = " + json);
  57. Assert.assertEquals("{\"u_id\":\"hello\"}", json);
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement