PageRenderTime 64ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/qt-prometheus/qt-prometheus
Java | 115 lines | 105 code | 6 blank | 4 comment | 43 complexity | 465e01e29a20ff91dfe4a0c1369f4266 MD5 | raw file
  1. package com.alibaba.fastjson.serializer;
  2. import com.alibaba.fastjson.annotation.JSONField;
  3. import com.alibaba.fastjson.util.FieldInfo;
  4. import java.util.Collection;
  5. public class ObjectFieldSerializer extends FieldSerializer
  6. {
  7. private ObjectSerializer fieldSerializer;
  8. private String format;
  9. private Class<?> runtimeFieldClass;
  10. boolean writeEnumUsingToString = false;
  11. boolean writeNullBooleanAsFalse = false;
  12. boolean writeNullListAsEmpty = false;
  13. boolean writeNullStringAsEmpty = false;
  14. private boolean writeNumberAsZero = false;
  15. public ObjectFieldSerializer(FieldInfo paramFieldInfo)
  16. {
  17. super(paramFieldInfo);
  18. paramFieldInfo = (JSONField)paramFieldInfo.getAnnotation(JSONField.class);
  19. if (paramFieldInfo != null)
  20. {
  21. this.format = paramFieldInfo.format();
  22. if (this.format.trim().length() == 0)
  23. this.format = null;
  24. paramFieldInfo = paramFieldInfo.serialzeFeatures();
  25. int j = paramFieldInfo.length;
  26. int i = 0;
  27. if (i < j)
  28. {
  29. Object localObject = paramFieldInfo[i];
  30. if (localObject == SerializerFeature.WriteNullNumberAsZero)
  31. this.writeNumberAsZero = true;
  32. while (true)
  33. {
  34. i += 1;
  35. break;
  36. if (localObject == SerializerFeature.WriteNullStringAsEmpty)
  37. this.writeNullStringAsEmpty = true;
  38. else if (localObject == SerializerFeature.WriteNullBooleanAsFalse)
  39. this.writeNullBooleanAsFalse = true;
  40. else if (localObject == SerializerFeature.WriteNullListAsEmpty)
  41. this.writeNullListAsEmpty = true;
  42. else if (localObject == SerializerFeature.WriteEnumUsingToString)
  43. this.writeEnumUsingToString = true;
  44. }
  45. }
  46. }
  47. }
  48. public void writeProperty(JSONSerializer paramJSONSerializer, Object paramObject)
  49. throws Exception
  50. {
  51. writePrefix(paramJSONSerializer);
  52. writeValue(paramJSONSerializer, paramObject);
  53. }
  54. public void writeValue(JSONSerializer paramJSONSerializer, Object paramObject)
  55. throws Exception
  56. {
  57. if (this.format != null)
  58. {
  59. paramJSONSerializer.writeWithFormat(paramObject, this.format);
  60. return;
  61. }
  62. if (this.fieldSerializer == null)
  63. if (paramObject != null)
  64. break label84;
  65. label84: for (this.runtimeFieldClass = this.fieldInfo.getFieldClass(); ; this.runtimeFieldClass = paramObject.getClass())
  66. {
  67. this.fieldSerializer = paramJSONSerializer.getObjectWriter(this.runtimeFieldClass);
  68. if (paramObject != null)
  69. break label196;
  70. if ((!this.writeNumberAsZero) || (!Number.class.isAssignableFrom(this.runtimeFieldClass)))
  71. break;
  72. paramJSONSerializer.getWriter().write('0');
  73. return;
  74. }
  75. if ((this.writeNullStringAsEmpty) && (String.class == this.runtimeFieldClass))
  76. {
  77. paramJSONSerializer.getWriter().write("\"\"");
  78. return;
  79. }
  80. if ((this.writeNullBooleanAsFalse) && (Boolean.class == this.runtimeFieldClass))
  81. {
  82. paramJSONSerializer.getWriter().write("false");
  83. return;
  84. }
  85. if ((this.writeNullListAsEmpty) && (Collection.class.isAssignableFrom(this.runtimeFieldClass)))
  86. {
  87. paramJSONSerializer.getWriter().write("[]");
  88. return;
  89. }
  90. this.fieldSerializer.write(paramJSONSerializer, null, this.fieldInfo.getName(), null);
  91. return;
  92. label196: if ((this.writeEnumUsingToString == true) && (this.runtimeFieldClass.isEnum()))
  93. {
  94. paramJSONSerializer.getWriter().writeString(((Enum)paramObject).name());
  95. return;
  96. }
  97. Class localClass = paramObject.getClass();
  98. if (localClass == this.runtimeFieldClass)
  99. {
  100. this.fieldSerializer.write(paramJSONSerializer, paramObject, this.fieldInfo.getName(), this.fieldInfo.getFieldType());
  101. return;
  102. }
  103. paramJSONSerializer.getObjectWriter(localClass).write(paramJSONSerializer, paramObject, this.fieldInfo.getName(), this.fieldInfo.getFieldType());
  104. }
  105. }
  106. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  107. * Qualified Name: com.alibaba.fastjson.serializer.ObjectFieldSerializer
  108. * JD-Core Version: 0.6.2
  109. */