PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/QingTingFanBianYi/src/com/alibaba/fastjson/serializer/DateSerializer.java

https://gitlab.com/qt-prometheus/qt-prometheus
Java | 120 lines | 112 code | 4 blank | 4 comment | 16 complexity | e220112304513c297e60bc5db8bc01ae MD5 | raw file
  1. package com.alibaba.fastjson.serializer;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.util.IOUtils;
  4. import java.io.IOException;
  5. import java.lang.reflect.Type;
  6. import java.text.DateFormat;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Calendar;
  9. import java.util.Date;
  10. public class DateSerializer
  11. implements ObjectSerializer
  12. {
  13. public static final DateSerializer instance = new DateSerializer();
  14. public void write(JSONSerializer paramJSONSerializer, Object paramObject1, Object paramObject2, Type paramType)
  15. throws IOException
  16. {
  17. paramObject2 = paramJSONSerializer.getWriter();
  18. if (paramObject1 == null)
  19. {
  20. paramObject2.writeNull();
  21. return;
  22. }
  23. if ((paramObject2.isEnabled(SerializerFeature.WriteClassName)) && (paramObject1.getClass() != paramType))
  24. {
  25. if (paramObject1.getClass() == Date.class)
  26. {
  27. paramObject2.write("new Date(");
  28. paramObject2.writeLongAndChar(((Date)paramObject1).getTime(), ')');
  29. return;
  30. }
  31. paramObject2.write('{');
  32. paramObject2.writeFieldName(JSON.DEFAULT_TYPE_KEY);
  33. paramJSONSerializer.write(paramObject1.getClass().getName());
  34. paramObject2.writeFieldValue(',', "val", ((Date)paramObject1).getTime());
  35. paramObject2.write('}');
  36. return;
  37. }
  38. paramType = (Date)paramObject1;
  39. if (paramObject2.isEnabled(SerializerFeature.WriteDateUseDateFormat))
  40. {
  41. paramObject1 = paramJSONSerializer.getDateFormat();
  42. paramJSONSerializer = paramObject1;
  43. if (paramObject1 == null)
  44. paramJSONSerializer = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT);
  45. paramObject2.writeString(paramJSONSerializer.format(paramType));
  46. return;
  47. }
  48. long l = paramType.getTime();
  49. if (paramJSONSerializer.isEnabled(SerializerFeature.UseISO8601DateFormat))
  50. {
  51. int i;
  52. int j;
  53. int k;
  54. int m;
  55. int n;
  56. int i1;
  57. if (paramJSONSerializer.isEnabled(SerializerFeature.UseSingleQuotes))
  58. {
  59. paramObject2.append('\'');
  60. paramObject1 = Calendar.getInstance();
  61. paramObject1.setTimeInMillis(l);
  62. i = paramObject1.get(1);
  63. j = paramObject1.get(2) + 1;
  64. k = paramObject1.get(5);
  65. m = paramObject1.get(11);
  66. n = paramObject1.get(12);
  67. i1 = paramObject1.get(13);
  68. int i2 = paramObject1.get(14);
  69. if (i2 == 0)
  70. break label355;
  71. paramObject1 = "0000-00-00T00:00:00.000".toCharArray();
  72. IOUtils.getChars(i2, 23, paramObject1);
  73. IOUtils.getChars(i1, 19, paramObject1);
  74. IOUtils.getChars(n, 16, paramObject1);
  75. IOUtils.getChars(m, 13, paramObject1);
  76. IOUtils.getChars(k, 10, paramObject1);
  77. IOUtils.getChars(j, 7, paramObject1);
  78. IOUtils.getChars(i, 4, paramObject1);
  79. }
  80. while (true)
  81. {
  82. paramObject2.write(paramObject1);
  83. if (!paramJSONSerializer.isEnabled(SerializerFeature.UseSingleQuotes))
  84. break label458;
  85. paramObject2.append('\'');
  86. return;
  87. paramObject2.append('"');
  88. break;
  89. label355: if ((i1 == 0) && (n == 0) && (m == 0))
  90. {
  91. paramObject1 = "0000-00-00".toCharArray();
  92. IOUtils.getChars(k, 10, paramObject1);
  93. IOUtils.getChars(j, 7, paramObject1);
  94. IOUtils.getChars(i, 4, paramObject1);
  95. }
  96. else
  97. {
  98. paramObject1 = "0000-00-00T00:00:00".toCharArray();
  99. IOUtils.getChars(i1, 19, paramObject1);
  100. IOUtils.getChars(n, 16, paramObject1);
  101. IOUtils.getChars(m, 13, paramObject1);
  102. IOUtils.getChars(k, 10, paramObject1);
  103. IOUtils.getChars(j, 7, paramObject1);
  104. IOUtils.getChars(i, 4, paramObject1);
  105. }
  106. }
  107. label458: paramObject2.append('"');
  108. return;
  109. }
  110. paramObject2.writeLong(l);
  111. }
  112. }
  113. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  114. * Qualified Name: com.alibaba.fastjson.serializer.DateSerializer
  115. * JD-Core Version: 0.6.2
  116. */