/src/test/java/com/alibaba/json/bvt/LongFieldTest_2.java

https://github.com/alibaba/fastjson · Java · 117 lines · 75 code · 42 blank · 0 comment · 0 complexity · 32c166a174a092e21501f92d7cf0941c MD5 · raw file

  1. package com.alibaba.json.bvt;
  2. import com.alibaba.fastjson.JSONReader;
  3. import org.junit.Assert;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.parser.Feature;
  6. import com.alibaba.fastjson.serializer.SerializerFeature;
  7. import junit.framework.TestCase;
  8. import java.io.StringReader;
  9. public class LongFieldTest_2 extends TestCase {
  10. public void test_min() throws Exception {
  11. V0 v = new V0();
  12. v.setValue(Long.MIN_VALUE);
  13. String text = JSON.toJSONString(v);
  14. V0 v1 = JSON.parseObject(text, V0.class);
  15. Assert.assertEquals(v1.getValue(), v.getValue());
  16. }
  17. public void test_min_reader() throws Exception {
  18. V0 v = new V0();
  19. v.setValue(Long.MIN_VALUE);
  20. String text = JSON.toJSONString(v);
  21. V0 v1 = new JSONReader(new StringReader(text)).readObject(V0.class);
  22. Assert.assertEquals(v1.getValue(), v.getValue());
  23. }
  24. public void test_max() throws Exception {
  25. V0 v = new V0();
  26. v.setValue(Long.MAX_VALUE);
  27. String text = JSON.toJSONString(v);
  28. V0 v1 = JSON.parseObject(text, V0.class);
  29. Assert.assertEquals(v1.getValue(), v.getValue());
  30. }
  31. public void test_max_reader() throws Exception {
  32. V0 v = new V0();
  33. v.setValue(Long.MAX_VALUE);
  34. String text = JSON.toJSONString(v);
  35. V0 v1 = new JSONReader(new StringReader(text)).readObject(V0.class);
  36. Assert.assertEquals(v1.getValue(), v.getValue());
  37. }
  38. public void test_min_array() throws Exception {
  39. V0 v = new V0();
  40. v.setValue(Long.MIN_VALUE);
  41. String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);
  42. V0 v1 = JSON.parseObject(text, V0.class, Feature.SupportArrayToBean);
  43. Assert.assertEquals(v1.getValue(), v.getValue());
  44. }
  45. public void test_min_array_reader() throws Exception {
  46. V0 v = new V0();
  47. v.setValue(Long.MIN_VALUE);
  48. String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);
  49. V0 v1 = new JSONReader(new StringReader(text), Feature.SupportArrayToBean).readObject(V0.class);
  50. Assert.assertEquals(v1.getValue(), v.getValue());
  51. }
  52. public void test_max_array() throws Exception {
  53. V0 v = new V0();
  54. v.setValue(Long.MAX_VALUE);
  55. String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);
  56. V0 v1 = JSON.parseObject(text, V0.class, Feature.SupportArrayToBean);
  57. Assert.assertEquals(v1.getValue(), v.getValue());
  58. }
  59. public void test_max_array_reader() throws Exception {
  60. V0 v = new V0();
  61. v.setValue(Long.MAX_VALUE);
  62. String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);
  63. V0 v1 = new JSONReader(new StringReader(text), Feature.SupportArrayToBean).readObject(V0.class);
  64. Assert.assertEquals(v1.getValue(), v.getValue());
  65. }
  66. public static class V0 {
  67. private Long value;
  68. public Long getValue() {
  69. return value;
  70. }
  71. public void setValue(Long value) {
  72. this.value = value;
  73. }
  74. }
  75. }