PageRenderTime 1363ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/qt-prometheus/qt-prometheus
Java | 254 lines | 238 code | 12 blank | 4 comment | 48 complexity | 44d55291766e71c51b534465cf80148e MD5 | raw file
  1. package com.alibaba.fastjson.serializer;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONException;
  4. import com.alibaba.fastjson.util.FieldInfo;
  5. import com.alibaba.fastjson.util.TypeUtils;
  6. import java.io.IOException;
  7. import java.lang.reflect.Field;
  8. import java.lang.reflect.Modifier;
  9. import java.lang.reflect.Type;
  10. import java.util.ArrayList;
  11. import java.util.HashMap;
  12. import java.util.Iterator;
  13. import java.util.List;
  14. import java.util.Map;
  15. public class JavaBeanSerializer
  16. implements ObjectSerializer
  17. {
  18. private final FieldSerializer[] getters;
  19. private final FieldSerializer[] sortedGetters;
  20. public JavaBeanSerializer(Class<?> paramClass)
  21. {
  22. this(paramClass, (Map)null);
  23. }
  24. public JavaBeanSerializer(Class<?> paramClass, Map<String, String> paramMap)
  25. {
  26. ArrayList localArrayList = new ArrayList();
  27. Iterator localIterator = TypeUtils.computeGetters(paramClass, paramMap, false).iterator();
  28. while (localIterator.hasNext())
  29. localArrayList.add(createFieldSerializer((FieldInfo)localIterator.next()));
  30. this.getters = ((FieldSerializer[])localArrayList.toArray(new FieldSerializer[localArrayList.size()]));
  31. localArrayList = new ArrayList();
  32. paramClass = TypeUtils.computeGetters(paramClass, paramMap, true).iterator();
  33. while (paramClass.hasNext())
  34. localArrayList.add(createFieldSerializer((FieldInfo)paramClass.next()));
  35. this.sortedGetters = ((FieldSerializer[])localArrayList.toArray(new FieldSerializer[localArrayList.size()]));
  36. }
  37. public JavaBeanSerializer(Class<?> paramClass, String[] paramArrayOfString)
  38. {
  39. this(paramClass, createAliasMap(paramArrayOfString));
  40. }
  41. static Map<String, String> createAliasMap(String[] paramArrayOfString)
  42. {
  43. HashMap localHashMap = new HashMap();
  44. int j = paramArrayOfString.length;
  45. int i = 0;
  46. while (i < j)
  47. {
  48. String str = paramArrayOfString[i];
  49. localHashMap.put(str, str);
  50. i += 1;
  51. }
  52. return localHashMap;
  53. }
  54. public FieldSerializer createFieldSerializer(FieldInfo paramFieldInfo)
  55. {
  56. if (paramFieldInfo.getFieldClass() == Number.class)
  57. return new NumberFieldSerializer(paramFieldInfo);
  58. return new ObjectFieldSerializer(paramFieldInfo);
  59. }
  60. public FieldSerializer[] getGetters()
  61. {
  62. return this.getters;
  63. }
  64. protected boolean isWriteClassName(JSONSerializer paramJSONSerializer, Object paramObject1, Type paramType, Object paramObject2)
  65. {
  66. return paramJSONSerializer.isWriteClassName(paramType, paramObject1);
  67. }
  68. public void write(JSONSerializer paramJSONSerializer, Object paramObject1, Object paramObject2, Type paramType)
  69. throws IOException
  70. {
  71. SerializeWriter localSerializeWriter = paramJSONSerializer.getWriter();
  72. if (paramObject1 == null)
  73. {
  74. localSerializeWriter.writeNull();
  75. return;
  76. }
  77. if (paramJSONSerializer.containsReference(paramObject1))
  78. {
  79. writeReference(paramJSONSerializer, paramObject1);
  80. return;
  81. }
  82. FieldSerializer[] arrayOfFieldSerializer;
  83. if (localSerializeWriter.isEnabled(SerializerFeature.SortField))
  84. arrayOfFieldSerializer = this.sortedGetters;
  85. SerialContext localSerialContext;
  86. boolean bool1;
  87. char c2;
  88. label80: char c1;
  89. label89: int j;
  90. int i;
  91. label176: label194: int k;
  92. label248: Object localObject;
  93. while (true)
  94. {
  95. localSerialContext = paramJSONSerializer.getContext();
  96. paramJSONSerializer.setContext(localSerialContext, paramObject1, paramObject2);
  97. bool1 = paramJSONSerializer.isWriteAsArray(paramObject1, paramType);
  98. if (bool1)
  99. {
  100. c2 = '[';
  101. if (!bool1)
  102. break label277;
  103. c1 = ']';
  104. }
  105. try
  106. {
  107. localSerializeWriter.append(c2);
  108. if ((arrayOfFieldSerializer.length > 0) && (localSerializeWriter.isEnabled(SerializerFeature.PrettyFormat)))
  109. {
  110. paramJSONSerializer.incrementIndent();
  111. paramJSONSerializer.println();
  112. }
  113. j = 0;
  114. i = j;
  115. if (!isWriteClassName(paramJSONSerializer, paramObject1, paramType, paramObject2))
  116. break label578;
  117. i = j;
  118. if (paramObject1.getClass() == paramType)
  119. break label578;
  120. localSerializeWriter.writeFieldName(JSON.DEFAULT_TYPE_KEY);
  121. paramJSONSerializer.write(paramObject1.getClass());
  122. i = 1;
  123. break label578;
  124. if (FilterUtils.writeBefore(paramJSONSerializer, paramObject1, c2) == ',')
  125. {
  126. i = 1;
  127. break label590;
  128. if (j >= arrayOfFieldSerializer.length)
  129. break label602;
  130. paramObject2 = arrayOfFieldSerializer[j];
  131. if (!paramJSONSerializer.isEnabled(SerializerFeature.SkipTransientField))
  132. break label296;
  133. paramType = paramObject2.getField();
  134. if (paramType == null)
  135. break label296;
  136. boolean bool2 = Modifier.isTransient(paramType.getModifiers());
  137. if (!bool2)
  138. break label296;
  139. k = i;
  140. }
  141. label277: label284: label296: String str;
  142. do
  143. {
  144. do
  145. {
  146. do
  147. {
  148. j += 1;
  149. i = k;
  150. break label194;
  151. arrayOfFieldSerializer = this.getters;
  152. break;
  153. c2 = '{';
  154. break label80;
  155. c1 = '}';
  156. break label89;
  157. c2 = '\000';
  158. break label176;
  159. i = 0;
  160. break label590;
  161. k = i;
  162. }
  163. while (!FilterUtils.applyName(paramJSONSerializer, paramObject1, paramObject2.getName()));
  164. paramType = paramObject2.getPropertyValue(paramObject1);
  165. k = i;
  166. }
  167. while (!FilterUtils.apply(paramJSONSerializer, paramObject1, paramObject2.getName(), paramType));
  168. str = FilterUtils.processKey(paramJSONSerializer, paramObject1, paramObject2.getName(), paramType);
  169. localObject = FilterUtils.processValue(paramJSONSerializer, paramObject1, paramObject2.getName(), paramType);
  170. if ((localObject != null) || (bool1) || (paramObject2.isWriteNull()))
  171. break label394;
  172. k = i;
  173. }
  174. while (!paramJSONSerializer.isEnabled(SerializerFeature.WriteMapNullValue));
  175. label394: if (i != 0)
  176. {
  177. localSerializeWriter.append(',');
  178. if (localSerializeWriter.isEnabled(SerializerFeature.PrettyFormat))
  179. paramJSONSerializer.println();
  180. }
  181. if (str != paramObject2.getName())
  182. {
  183. if (!bool1)
  184. localSerializeWriter.writeFieldName(str);
  185. paramJSONSerializer.write(localObject);
  186. break label596;
  187. }
  188. if (paramType != localObject)
  189. if (!bool1)
  190. paramObject2.writePrefix(paramJSONSerializer);
  191. }
  192. catch (Exception paramObject1)
  193. {
  194. throw new JSONException("write javaBean error", paramObject1);
  195. }
  196. finally
  197. {
  198. paramJSONSerializer.setContext(localSerialContext);
  199. }
  200. }
  201. if (!bool1)
  202. paramObject2.writeProperty(paramJSONSerializer, localObject);
  203. else
  204. paramObject2.writeValue(paramJSONSerializer, localObject);
  205. while (true)
  206. {
  207. label524: FilterUtils.writeAfter(paramJSONSerializer, paramObject1, c2);
  208. if ((arrayOfFieldSerializer.length > 0) && (localSerializeWriter.isEnabled(SerializerFeature.PrettyFormat)))
  209. {
  210. paramJSONSerializer.decrementIdent();
  211. paramJSONSerializer.println();
  212. }
  213. localSerializeWriter.append(c1);
  214. paramJSONSerializer.setContext(localSerialContext);
  215. return;
  216. label578: label590: label596: label602:
  217. do
  218. {
  219. c2 = '\000';
  220. break label524;
  221. if (i == 0)
  222. break label284;
  223. c2 = ',';
  224. break;
  225. j = 0;
  226. break label194;
  227. k = 1;
  228. break label248;
  229. }
  230. while (i == 0);
  231. c2 = ',';
  232. }
  233. }
  234. public void writeReference(JSONSerializer paramJSONSerializer, Object paramObject)
  235. {
  236. paramJSONSerializer.writeReference(paramObject);
  237. }
  238. }
  239. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  240. * Qualified Name: com.alibaba.fastjson.serializer.JavaBeanSerializer
  241. * JD-Core Version: 0.6.2
  242. */