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

https://gitlab.com/qt-prometheus/qt-prometheus · Java · 185 lines · 169 code · 12 blank · 4 comment · 13 complexity · b9f249b9d27b9e18bc1c0a1236441f6c 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.annotation.JSONType;
  5. import com.alibaba.fastjson.util.ASMUtils;
  6. import com.alibaba.fastjson.util.IdentityHashMap;
  7. import java.io.File;
  8. import java.io.Serializable;
  9. import java.lang.ref.SoftReference;
  10. import java.lang.ref.WeakReference;
  11. import java.lang.reflect.Modifier;
  12. import java.lang.reflect.Type;
  13. import java.math.BigDecimal;
  14. import java.math.BigInteger;
  15. import java.net.Inet4Address;
  16. import java.net.Inet6Address;
  17. import java.net.InetAddress;
  18. import java.net.InetSocketAddress;
  19. import java.net.URI;
  20. import java.net.URL;
  21. import java.nio.charset.Charset;
  22. import java.text.SimpleDateFormat;
  23. import java.util.Locale;
  24. import java.util.TimeZone;
  25. import java.util.UUID;
  26. import java.util.concurrent.atomic.AtomicBoolean;
  27. import java.util.concurrent.atomic.AtomicInteger;
  28. import java.util.concurrent.atomic.AtomicIntegerArray;
  29. import java.util.concurrent.atomic.AtomicLong;
  30. import java.util.concurrent.atomic.AtomicLongArray;
  31. import java.util.concurrent.atomic.AtomicReference;
  32. import java.util.regex.Pattern;
  33. public class SerializeConfig extends IdentityHashMap<Type, ObjectSerializer>
  34. {
  35. private static final SerializeConfig globalInstance = new SerializeConfig();
  36. private boolean asm;
  37. private final ASMSerializerFactory asmFactory;
  38. private String typeKey;
  39. public SerializeConfig()
  40. {
  41. this(1024);
  42. }
  43. public SerializeConfig(int paramInt)
  44. {
  45. super(paramInt);
  46. boolean bool;
  47. if (!ASMUtils.isAndroid())
  48. bool = true;
  49. while (true)
  50. {
  51. this.asm = bool;
  52. this.asmFactory = new ASMSerializerFactory();
  53. this.typeKey = JSON.DEFAULT_TYPE_KEY;
  54. put(Boolean.class, BooleanSerializer.instance);
  55. put(Character.class, CharacterSerializer.instance);
  56. put(Byte.class, ByteSerializer.instance);
  57. put(Short.class, ShortSerializer.instance);
  58. put(Integer.class, IntegerSerializer.instance);
  59. put(Long.class, LongSerializer.instance);
  60. put(Float.class, FloatSerializer.instance);
  61. put(Double.class, DoubleSerializer.instance);
  62. put(BigDecimal.class, BigDecimalSerializer.instance);
  63. put(BigInteger.class, BigIntegerSerializer.instance);
  64. put(String.class, StringSerializer.instance);
  65. put([B.class, ByteArraySerializer.instance);
  66. put([S.class, ShortArraySerializer.instance);
  67. put([I.class, IntArraySerializer.instance);
  68. put([J.class, LongArraySerializer.instance);
  69. put([F.class, FloatArraySerializer.instance);
  70. put([D.class, DoubleArraySerializer.instance);
  71. put([Z.class, BooleanArraySerializer.instance);
  72. put([C.class, CharArraySerializer.instance);
  73. put([Ljava.lang.Object.class, ObjectArraySerializer.instance);
  74. put(Class.class, ClassSerializer.instance);
  75. put(SimpleDateFormat.class, DateFormatSerializer.instance);
  76. put(Locale.class, LocaleSerializer.instance);
  77. put(TimeZone.class, TimeZoneSerializer.instance);
  78. put(UUID.class, UUIDSerializer.instance);
  79. put(InetAddress.class, InetAddressSerializer.instance);
  80. put(Inet4Address.class, InetAddressSerializer.instance);
  81. put(Inet6Address.class, InetAddressSerializer.instance);
  82. put(InetSocketAddress.class, InetSocketAddressSerializer.instance);
  83. put(File.class, FileSerializer.instance);
  84. put(URI.class, URISerializer.instance);
  85. put(URL.class, URLSerializer.instance);
  86. put(Appendable.class, AppendableSerializer.instance);
  87. put(StringBuffer.class, AppendableSerializer.instance);
  88. put(StringBuilder.class, AppendableSerializer.instance);
  89. put(Pattern.class, PatternSerializer.instance);
  90. put(Charset.class, CharsetSerializer.instance);
  91. put(AtomicBoolean.class, AtomicBooleanSerializer.instance);
  92. put(AtomicInteger.class, AtomicIntegerSerializer.instance);
  93. put(AtomicLong.class, AtomicLongSerializer.instance);
  94. put(AtomicReference.class, ReferenceSerializer.instance);
  95. put(AtomicIntegerArray.class, AtomicIntegerArraySerializer.instance);
  96. put(AtomicLongArray.class, AtomicLongArraySerializer.instance);
  97. put(WeakReference.class, ReferenceSerializer.instance);
  98. put(SoftReference.class, ReferenceSerializer.instance);
  99. try
  100. {
  101. put(Class.forName("java.awt.Color"), ColorSerializer.instance);
  102. put(Class.forName("java.awt.Font"), FontSerializer.instance);
  103. put(Class.forName("java.awt.Point"), PointSerializer.instance);
  104. put(Class.forName("java.awt.Rectangle"), RectangleSerializer.instance);
  105. return;
  106. bool = false;
  107. }
  108. catch (Throwable localThrowable)
  109. {
  110. }
  111. }
  112. }
  113. public static final SerializeConfig getGlobalInstance()
  114. {
  115. return globalInstance;
  116. }
  117. public final ObjectSerializer createASMSerializer(Class<?> paramClass)
  118. throws Exception
  119. {
  120. return this.asmFactory.createJavaBeanSerializer(paramClass);
  121. }
  122. public ObjectSerializer createJavaBeanSerializer(Class<?> paramClass)
  123. {
  124. if (!Modifier.isPublic(paramClass.getModifiers()))
  125. return new JavaBeanSerializer(paramClass);
  126. boolean bool1 = this.asm;
  127. if (((bool1) && (this.asmFactory.isExternalClass(paramClass))) || (paramClass == Serializable.class) || (paramClass == Object.class))
  128. bool1 = false;
  129. Object localObject = (JSONType)paramClass.getAnnotation(JSONType.class);
  130. boolean bool2 = bool1;
  131. if (localObject != null)
  132. {
  133. bool2 = bool1;
  134. if (!((JSONType)localObject).asm())
  135. bool2 = false;
  136. }
  137. if (bool2)
  138. try
  139. {
  140. localObject = createASMSerializer(paramClass);
  141. return localObject;
  142. }
  143. catch (ClassCastException localClassCastException)
  144. {
  145. return new JavaBeanSerializer(paramClass);
  146. }
  147. catch (Throwable localThrowable)
  148. {
  149. throw new JSONException("create asm serializer error, class " + paramClass, localThrowable);
  150. }
  151. return new JavaBeanSerializer(paramClass);
  152. }
  153. public String getTypeKey()
  154. {
  155. return this.typeKey;
  156. }
  157. public boolean isAsmEnable()
  158. {
  159. return this.asm;
  160. }
  161. public void setAsmEnable(boolean paramBoolean)
  162. {
  163. this.asm = paramBoolean;
  164. }
  165. public void setTypeKey(String paramString)
  166. {
  167. this.typeKey = paramString;
  168. }
  169. }
  170. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  171. * Qualified Name: com.alibaba.fastjson.serializer.SerializeConfig
  172. * JD-Core Version: 0.6.2
  173. */