/src/test/java/com/alibaba/json/bvt/bug/Bug_for_lenolix_8.java

https://github.com/alibaba/fastjson · Java · 112 lines · 79 code · 30 blank · 3 comment · 0 complexity · 2d3d039bc232e7c5a81f6a82aec88c28 MD5 · raw file

  1. package com.alibaba.json.bvt.bug;
  2. import java.io.Serializable;
  3. import java.text.DateFormat;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import java.util.Locale;
  8. import java.util.Map;
  9. import java.util.TimeZone;
  10. import junit.framework.TestCase;
  11. import com.alibaba.fastjson.JSON;
  12. import com.alibaba.fastjson.serializer.SerializerFeature;
  13. public class Bug_for_lenolix_8 extends TestCase {
  14. protected void setUp() throws Exception {
  15. JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
  16. JSON.defaultLocale = Locale.CHINA;
  17. com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.Bug_for_lenolix_8.");
  18. }
  19. public void test_for_objectKey() throws Exception {
  20. DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", JSON.defaultLocale);
  21. simpleDateFormat.setTimeZone(JSON.defaultTimeZone);
  22. Map<Integer, User> map = new HashMap<Integer, User>();
  23. User user = new User();
  24. user.setId(1);
  25. user.setIsBoy(true);
  26. user.setName("leno.lix");
  27. user.setBirthDay(simpleDateFormat.parse("2012-03-07 22:38:21"));
  28. user.setGmtCreate(new java.sql.Date(simpleDateFormat.parse("2012-02-03 22:38:21").getTime()));
  29. map.put(1, user);
  30. String mapJson = JSON.toJSONString(map, SerializerFeature.WriteClassName, SerializerFeature.WriteMapNullValue);
  31. System.out.println(mapJson);
  32. Object object = JSON.parse(mapJson);
  33. }
  34. public static class User implements Serializable {
  35. /**
  36. *
  37. */
  38. private static final long serialVersionUID = 6192533820796587011L;
  39. private Integer id;
  40. private String name;
  41. private Boolean isBoy;
  42. private Date birthDay;
  43. private java.sql.Date gmtCreate;
  44. private java.sql.Timestamp gmtModified;
  45. public Integer getId() {
  46. return id;
  47. }
  48. public void setId(Integer id) {
  49. this.id = id;
  50. }
  51. public String getName() {
  52. return name;
  53. }
  54. public void setName(String name) {
  55. this.name = name;
  56. }
  57. public Boolean getIsBoy() {
  58. return isBoy;
  59. }
  60. public void setIsBoy(Boolean isBoy) {
  61. this.isBoy = isBoy;
  62. }
  63. public Date getBirthDay() {
  64. return birthDay;
  65. }
  66. public void setBirthDay(Date birthDay) {
  67. this.birthDay = birthDay;
  68. }
  69. public java.sql.Date getGmtCreate() {
  70. return gmtCreate;
  71. }
  72. public void setGmtCreate(java.sql.Date gmtCreate) {
  73. this.gmtCreate = gmtCreate;
  74. }
  75. public java.sql.Timestamp getGmtModified() {
  76. return gmtModified;
  77. }
  78. public void setGmtModified(java.sql.Timestamp gmtModified) {
  79. this.gmtModified = gmtModified;
  80. }
  81. }
  82. }