PageRenderTime 3230ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/QingTingFanBianYi/src/com/alibaba/fastjson/util/TypeUtils.java

https://gitlab.com/qt-prometheus/qt-prometheus
Java | 1039 lines | 1001 code | 34 blank | 4 comment | 374 complexity | a9c48457ee5924aecd4a8a7b2906b7f3 MD5 | raw file
  1. package com.alibaba.fastjson.util;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONException;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.alibaba.fastjson.annotation.JSONField;
  6. import com.alibaba.fastjson.annotation.JSONType;
  7. import com.alibaba.fastjson.parser.JSONScanner;
  8. import com.alibaba.fastjson.parser.ParserConfig;
  9. import com.alibaba.fastjson.parser.deserializer.FieldDeserializer;
  10. import java.beans.Introspector;
  11. import java.lang.reflect.Array;
  12. import java.lang.reflect.Constructor;
  13. import java.lang.reflect.Field;
  14. import java.lang.reflect.Method;
  15. import java.lang.reflect.Modifier;
  16. import java.lang.reflect.ParameterizedType;
  17. import java.lang.reflect.Proxy;
  18. import java.lang.reflect.Type;
  19. import java.lang.reflect.TypeVariable;
  20. import java.lang.reflect.WildcardType;
  21. import java.math.BigDecimal;
  22. import java.math.BigInteger;
  23. import java.sql.Timestamp;
  24. import java.text.ParseException;
  25. import java.text.SimpleDateFormat;
  26. import java.util.ArrayList;
  27. import java.util.Calendar;
  28. import java.util.Collection;
  29. import java.util.Collections;
  30. import java.util.HashMap;
  31. import java.util.Iterator;
  32. import java.util.LinkedHashMap;
  33. import java.util.List;
  34. import java.util.Map;
  35. import java.util.Map.Entry;
  36. import java.util.Set;
  37. import java.util.concurrent.ConcurrentHashMap;
  38. import java.util.concurrent.ConcurrentMap;
  39. public class TypeUtils
  40. {
  41. public static boolean compatibleWithJavaBean = false;
  42. private static ConcurrentMap<String, Class<?>> mappings = new ConcurrentHashMap();
  43. static
  44. {
  45. addBaseClassMappings();
  46. }
  47. public static void addBaseClassMappings()
  48. {
  49. mappings.put("byte", Byte.TYPE);
  50. mappings.put("short", Short.TYPE);
  51. mappings.put("int", Integer.TYPE);
  52. mappings.put("long", Long.TYPE);
  53. mappings.put("float", Float.TYPE);
  54. mappings.put("double", Double.TYPE);
  55. mappings.put("boolean", Boolean.TYPE);
  56. mappings.put("char", Character.TYPE);
  57. mappings.put("[byte", [B.class);
  58. mappings.put("[short", [S.class);
  59. mappings.put("[int", [I.class);
  60. mappings.put("[long", [J.class);
  61. mappings.put("[float", [F.class);
  62. mappings.put("[double", [D.class);
  63. mappings.put("[boolean", [Z.class);
  64. mappings.put("[char", [C.class);
  65. mappings.put(HashMap.class.getName(), HashMap.class);
  66. }
  67. public static void addClassMapping(String paramString, Class<?> paramClass)
  68. {
  69. String str = paramString;
  70. if (paramString == null)
  71. str = paramClass.getName();
  72. mappings.put(str, paramClass);
  73. }
  74. public static final <T> T cast(Object paramObject, Class<T> paramClass, ParserConfig paramParserConfig)
  75. {
  76. Object localObject;
  77. if (paramObject == null)
  78. localObject = null;
  79. do
  80. {
  81. Map localMap;
  82. do
  83. {
  84. do
  85. {
  86. do
  87. {
  88. return localObject;
  89. if (paramClass == null)
  90. throw new IllegalArgumentException("clazz is null");
  91. localObject = paramObject;
  92. }
  93. while (paramClass == paramObject.getClass());
  94. if (!(paramObject instanceof Map))
  95. break;
  96. localObject = paramObject;
  97. }
  98. while (paramClass == Map.class);
  99. localMap = (Map)paramObject;
  100. if (paramClass != Object.class)
  101. break;
  102. localObject = paramObject;
  103. }
  104. while (!localMap.containsKey(JSON.DEFAULT_TYPE_KEY));
  105. return castToJavaBean((Map)paramObject, paramClass, paramParserConfig);
  106. if ((paramClass.isArray()) && ((paramObject instanceof Collection)))
  107. {
  108. localObject = (Collection)paramObject;
  109. int i = 0;
  110. paramObject = Array.newInstance(paramClass.getComponentType(), ((Collection)localObject).size());
  111. localObject = ((Collection)localObject).iterator();
  112. while (((Iterator)localObject).hasNext())
  113. {
  114. Array.set(paramObject, i, cast(((Iterator)localObject).next(), paramClass.getComponentType(), paramParserConfig));
  115. i += 1;
  116. }
  117. return paramObject;
  118. }
  119. localObject = paramObject;
  120. }
  121. while (paramClass.isAssignableFrom(paramObject.getClass()));
  122. if ((paramClass == Boolean.TYPE) || (paramClass == Boolean.class))
  123. return castToBoolean(paramObject);
  124. if ((paramClass == Byte.TYPE) || (paramClass == Byte.class))
  125. return castToByte(paramObject);
  126. if ((paramClass == Short.TYPE) || (paramClass == Short.class))
  127. return castToShort(paramObject);
  128. if ((paramClass == Integer.TYPE) || (paramClass == Integer.class))
  129. return castToInt(paramObject);
  130. if ((paramClass == Long.TYPE) || (paramClass == Long.class))
  131. return castToLong(paramObject);
  132. if ((paramClass == Float.TYPE) || (paramClass == Float.class))
  133. return castToFloat(paramObject);
  134. if ((paramClass == Double.TYPE) || (paramClass == Double.class))
  135. return castToDouble(paramObject);
  136. if (paramClass == String.class)
  137. return castToString(paramObject);
  138. if (paramClass == BigDecimal.class)
  139. return castToBigDecimal(paramObject);
  140. if (paramClass == BigInteger.class)
  141. return castToBigInteger(paramObject);
  142. if (paramClass == java.util.Date.class)
  143. return castToDate(paramObject);
  144. if (paramClass == java.sql.Date.class)
  145. return castToSqlDate(paramObject);
  146. if (paramClass == Timestamp.class)
  147. return castToTimestamp(paramObject);
  148. if (paramClass.isEnum())
  149. return castToEnum(paramObject, paramClass, paramParserConfig);
  150. if (Calendar.class.isAssignableFrom(paramClass))
  151. {
  152. paramParserConfig = castToDate(paramObject);
  153. if (paramClass == Calendar.class)
  154. paramObject = Calendar.getInstance();
  155. while (true)
  156. {
  157. paramObject.setTime(paramParserConfig);
  158. return paramObject;
  159. try
  160. {
  161. paramObject = (Calendar)paramClass.newInstance();
  162. }
  163. catch (Exception paramObject)
  164. {
  165. throw new JSONException("can not cast to : " + paramClass.getName(), paramObject);
  166. }
  167. }
  168. }
  169. if (((paramObject instanceof String)) && (((String)paramObject).length() == 0))
  170. return null;
  171. throw new JSONException("can not cast to : " + paramClass.getName());
  172. }
  173. public static final <T> T cast(Object paramObject, ParameterizedType paramParameterizedType, ParserConfig paramParserConfig)
  174. {
  175. Object localObject2 = paramParameterizedType.getRawType();
  176. Type localType;
  177. Object localObject1;
  178. if ((localObject2 == List.class) || (localObject2 == ArrayList.class))
  179. {
  180. localType = paramParameterizedType.getActualTypeArguments()[0];
  181. if ((paramObject instanceof Iterable))
  182. {
  183. paramParameterizedType = new ArrayList();
  184. localObject1 = ((Iterable)paramObject).iterator();
  185. while (true)
  186. {
  187. paramObject = paramParameterizedType;
  188. if (!((Iterator)localObject1).hasNext())
  189. break;
  190. paramParameterizedType.add(cast(((Iterator)localObject1).next(), localType, paramParserConfig));
  191. }
  192. }
  193. }
  194. if ((localObject2 == Map.class) || (localObject2 == HashMap.class))
  195. {
  196. localType = paramParameterizedType.getActualTypeArguments()[0];
  197. localObject1 = paramParameterizedType.getActualTypeArguments()[1];
  198. if ((paramObject instanceof Map))
  199. {
  200. paramParameterizedType = new HashMap();
  201. paramObject = ((Map)paramObject).entrySet().iterator();
  202. while (paramObject.hasNext())
  203. {
  204. localObject2 = (Map.Entry)paramObject.next();
  205. paramParameterizedType.put(cast(((Map.Entry)localObject2).getKey(), localType, paramParserConfig), cast(((Map.Entry)localObject2).getValue(), (Type)localObject1, paramParserConfig));
  206. }
  207. paramObject = paramParameterizedType;
  208. return paramObject;
  209. }
  210. }
  211. if (((paramObject instanceof String)) && (((String)paramObject).length() == 0))
  212. return null;
  213. if ((paramParameterizedType.getActualTypeArguments().length == 1) && ((paramParameterizedType.getActualTypeArguments()[0] instanceof WildcardType)))
  214. return cast(paramObject, (Type)localObject2, paramParserConfig);
  215. throw new JSONException("can not cast to : " + paramParameterizedType);
  216. }
  217. public static final <T> T cast(Object paramObject, Type paramType, ParserConfig paramParserConfig)
  218. {
  219. if (paramObject == null)
  220. paramObject = null;
  221. do
  222. {
  223. return paramObject;
  224. if ((paramType instanceof Class))
  225. return cast(paramObject, (Class)paramType, paramParserConfig);
  226. if ((paramType instanceof ParameterizedType))
  227. return cast(paramObject, (ParameterizedType)paramType, paramParserConfig);
  228. if (((paramObject instanceof String)) && (((String)paramObject).length() == 0))
  229. return null;
  230. }
  231. while ((paramType instanceof TypeVariable));
  232. throw new JSONException("can not cast to : " + paramType);
  233. }
  234. public static final BigDecimal castToBigDecimal(Object paramObject)
  235. {
  236. if (paramObject == null)
  237. return null;
  238. if ((paramObject instanceof BigDecimal))
  239. return (BigDecimal)paramObject;
  240. if ((paramObject instanceof BigInteger))
  241. return new BigDecimal((BigInteger)paramObject);
  242. paramObject = paramObject.toString();
  243. if (paramObject.length() == 0)
  244. return null;
  245. return new BigDecimal(paramObject);
  246. }
  247. public static final BigInteger castToBigInteger(Object paramObject)
  248. {
  249. if (paramObject == null)
  250. return null;
  251. if ((paramObject instanceof BigInteger))
  252. return (BigInteger)paramObject;
  253. if (((paramObject instanceof Float)) || ((paramObject instanceof Double)))
  254. return BigInteger.valueOf(((Number)paramObject).longValue());
  255. paramObject = paramObject.toString();
  256. if (paramObject.length() == 0)
  257. return null;
  258. return new BigInteger(paramObject);
  259. }
  260. public static final Boolean castToBoolean(Object paramObject)
  261. {
  262. boolean bool = true;
  263. if (paramObject == null)
  264. return null;
  265. if ((paramObject instanceof Boolean))
  266. return (Boolean)paramObject;
  267. if ((paramObject instanceof Number))
  268. {
  269. if (((Number)paramObject).intValue() == 1);
  270. while (true)
  271. {
  272. return Boolean.valueOf(bool);
  273. bool = false;
  274. }
  275. }
  276. if ((paramObject instanceof String))
  277. {
  278. String str = (String)paramObject;
  279. if (str.length() == 0)
  280. return null;
  281. if ("true".equals(str))
  282. return Boolean.TRUE;
  283. if ("false".equals(str))
  284. return Boolean.FALSE;
  285. if ("1".equals(str))
  286. return Boolean.TRUE;
  287. }
  288. throw new JSONException("can not cast to int, value : " + paramObject);
  289. }
  290. public static final Byte castToByte(Object paramObject)
  291. {
  292. if (paramObject == null);
  293. do
  294. {
  295. return null;
  296. if ((paramObject instanceof Number))
  297. return Byte.valueOf(((Number)paramObject).byteValue());
  298. if (!(paramObject instanceof String))
  299. break;
  300. paramObject = (String)paramObject;
  301. }
  302. while (paramObject.length() == 0);
  303. return Byte.valueOf(Byte.parseByte(paramObject));
  304. throw new JSONException("can not cast to byte, value : " + paramObject);
  305. }
  306. public static final byte[] castToBytes(Object paramObject)
  307. {
  308. if ((paramObject instanceof byte[]))
  309. return (byte[])paramObject;
  310. if ((paramObject instanceof String))
  311. return Base64.decodeFast((String)paramObject);
  312. throw new JSONException("can not cast to int, value : " + paramObject);
  313. }
  314. public static final Character castToChar(Object paramObject)
  315. {
  316. if (paramObject == null)
  317. return null;
  318. if ((paramObject instanceof Character))
  319. return (Character)paramObject;
  320. if ((paramObject instanceof String))
  321. {
  322. String str = (String)paramObject;
  323. if (str.length() == 0)
  324. return null;
  325. if (str.length() != 1)
  326. throw new JSONException("can not cast to byte, value : " + paramObject);
  327. return Character.valueOf(str.charAt(0));
  328. }
  329. throw new JSONException("can not cast to byte, value : " + paramObject);
  330. }
  331. public static final java.util.Date castToDate(Object paramObject)
  332. {
  333. if (paramObject == null)
  334. return null;
  335. if ((paramObject instanceof Calendar))
  336. return ((Calendar)paramObject).getTime();
  337. if ((paramObject instanceof java.util.Date))
  338. return (java.util.Date)paramObject;
  339. long l = -1L;
  340. if ((paramObject instanceof Number))
  341. l = ((Number)paramObject).longValue();
  342. if ((paramObject instanceof String))
  343. {
  344. String str = (String)paramObject;
  345. if (str.indexOf('-') != -1)
  346. {
  347. if (str.length() == JSON.DEFFAULT_DATE_FORMAT.length())
  348. paramObject = JSON.DEFFAULT_DATE_FORMAT;
  349. while (true)
  350. {
  351. paramObject = new SimpleDateFormat(paramObject);
  352. try
  353. {
  354. paramObject = paramObject.parse(str);
  355. return paramObject;
  356. if (str.length() == 10)
  357. paramObject = "yyyy-MM-dd";
  358. else if (str.length() == "yyyy-MM-dd HH:mm:ss".length())
  359. paramObject = "yyyy-MM-dd HH:mm:ss";
  360. else
  361. paramObject = "yyyy-MM-dd HH:mm:ss.SSS";
  362. }
  363. catch (ParseException paramObject)
  364. {
  365. throw new JSONException("can not cast to Date, value : " + str);
  366. }
  367. }
  368. }
  369. if (str.length() == 0)
  370. return null;
  371. l = Long.parseLong(str);
  372. }
  373. if (l < 0L)
  374. throw new JSONException("can not cast to Date, value : " + paramObject);
  375. return new java.util.Date(l);
  376. }
  377. public static final Double castToDouble(Object paramObject)
  378. {
  379. if (paramObject == null);
  380. do
  381. {
  382. return null;
  383. if ((paramObject instanceof Number))
  384. return Double.valueOf(((Number)paramObject).doubleValue());
  385. if (!(paramObject instanceof String))
  386. break;
  387. paramObject = paramObject.toString();
  388. }
  389. while (paramObject.length() == 0);
  390. return Double.valueOf(Double.parseDouble(paramObject));
  391. throw new JSONException("can not cast to double, value : " + paramObject);
  392. }
  393. public static final <T> T castToEnum(Object paramObject, Class<T> paramClass, ParserConfig paramParserConfig)
  394. {
  395. try
  396. {
  397. if ((paramObject instanceof String))
  398. {
  399. paramObject = (String)paramObject;
  400. if (paramObject.length() == 0)
  401. return null;
  402. return Enum.valueOf(paramClass, paramObject);
  403. }
  404. if ((paramObject instanceof Number))
  405. {
  406. int j = ((Number)paramObject).intValue();
  407. paramObject = (Object[])paramClass.getMethod("values", new Class[0]).invoke(null, new Object[0]);
  408. int k = paramObject.length;
  409. int i = 0;
  410. while (i < k)
  411. {
  412. paramParserConfig = (Enum)paramObject[i];
  413. int m = paramParserConfig.ordinal();
  414. if (m == j)
  415. break label172;
  416. i += 1;
  417. }
  418. }
  419. }
  420. catch (Exception paramObject)
  421. {
  422. throw new JSONException("can not cast to : " + paramClass.getName(), paramObject);
  423. }
  424. throw new JSONException("can not cast to : " + paramClass.getName());
  425. label172: return paramParserConfig;
  426. }
  427. public static final Float castToFloat(Object paramObject)
  428. {
  429. if (paramObject == null);
  430. do
  431. {
  432. return null;
  433. if ((paramObject instanceof Number))
  434. return Float.valueOf(((Number)paramObject).floatValue());
  435. if (!(paramObject instanceof String))
  436. break;
  437. paramObject = paramObject.toString();
  438. }
  439. while (paramObject.length() == 0);
  440. return Float.valueOf(Float.parseFloat(paramObject));
  441. throw new JSONException("can not cast to float, value : " + paramObject);
  442. }
  443. public static final Integer castToInt(Object paramObject)
  444. {
  445. if (paramObject == null)
  446. return null;
  447. if ((paramObject instanceof Integer))
  448. return (Integer)paramObject;
  449. if ((paramObject instanceof Number))
  450. return Integer.valueOf(((Number)paramObject).intValue());
  451. if ((paramObject instanceof String))
  452. {
  453. paramObject = (String)paramObject;
  454. if (paramObject.length() == 0)
  455. return null;
  456. return Integer.valueOf(Integer.parseInt(paramObject));
  457. }
  458. throw new JSONException("can not cast to int, value : " + paramObject);
  459. }
  460. public static final <T> T castToJavaBean(Object paramObject, Class<T> paramClass)
  461. {
  462. return cast(paramObject, paramClass, ParserConfig.getGlobalInstance());
  463. }
  464. public static final <T> T castToJavaBean(Map<String, Object> paramMap, Class<T> paramClass, ParserConfig paramParserConfig)
  465. {
  466. if (paramClass == StackTraceElement.class);
  467. Object localObject2;
  468. try
  469. {
  470. paramClass = (String)paramMap.get("className");
  471. paramParserConfig = (String)paramMap.get("methodName");
  472. localObject1 = (String)paramMap.get("fileName");
  473. paramMap = (Number)paramMap.get("lineNumber");
  474. if (paramMap == null);
  475. for (int i = 0; ; i = paramMap.intValue())
  476. return new StackTraceElement(paramClass, paramParserConfig, (String)localObject1, i);
  477. localObject1 = paramMap.get(JSON.DEFAULT_TYPE_KEY);
  478. if (!(localObject1 instanceof String))
  479. break label180;
  480. localObject1 = (String)localObject1;
  481. localObject2 = loadClass((String)localObject1);
  482. if (localObject2 == null)
  483. throw new ClassNotFoundException((String)localObject1 + " not found");
  484. }
  485. catch (Exception paramMap)
  486. {
  487. throw new JSONException(paramMap.getMessage(), paramMap);
  488. }
  489. if (!localObject2.equals(paramClass))
  490. return castToJavaBean(paramMap, (Class)localObject2, paramParserConfig);
  491. label180: if (paramClass.isInterface())
  492. {
  493. if ((paramMap instanceof JSONObject));
  494. for (paramMap = (JSONObject)paramMap; ; paramMap = new JSONObject(paramMap))
  495. return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] { paramClass }, paramMap);
  496. }
  497. Object localObject1 = paramParserConfig;
  498. if (paramParserConfig == null)
  499. localObject1 = ParserConfig.getGlobalInstance();
  500. paramParserConfig = ((ParserConfig)localObject1).getFieldDeserializers(paramClass);
  501. paramClass = paramClass.getDeclaredConstructor(new Class[0]);
  502. if (!paramClass.isAccessible())
  503. paramClass.setAccessible(true);
  504. paramClass = paramClass.newInstance(new Object[0]);
  505. paramParserConfig = paramParserConfig.entrySet().iterator();
  506. while (paramParserConfig.hasNext())
  507. {
  508. localObject2 = (Map.Entry)paramParserConfig.next();
  509. Object localObject3 = (String)((Map.Entry)localObject2).getKey();
  510. localObject2 = (FieldDeserializer)((Map.Entry)localObject2).getValue();
  511. if (paramMap.containsKey(localObject3))
  512. {
  513. localObject3 = paramMap.get(localObject3);
  514. Method localMethod = ((FieldDeserializer)localObject2).getMethod();
  515. if (localMethod != null)
  516. {
  517. localMethod.invoke(paramClass, new Object[] { cast(localObject3, localMethod.getGenericParameterTypes()[0], (ParserConfig)localObject1) });
  518. }
  519. else
  520. {
  521. localObject2 = ((FieldDeserializer)localObject2).getField();
  522. ((Field)localObject2).set(paramClass, cast(localObject3, ((Field)localObject2).getGenericType(), (ParserConfig)localObject1));
  523. }
  524. }
  525. }
  526. return paramClass;
  527. }
  528. public static final Long castToLong(Object paramObject)
  529. {
  530. if (paramObject == null);
  531. Object localObject;
  532. do
  533. {
  534. return null;
  535. if ((paramObject instanceof Number))
  536. return Long.valueOf(((Number)paramObject).longValue());
  537. if (!(paramObject instanceof String))
  538. break;
  539. localObject = (String)paramObject;
  540. }
  541. while (((String)localObject).length() == 0);
  542. try
  543. {
  544. long l = Long.parseLong((String)localObject);
  545. return Long.valueOf(l);
  546. }
  547. catch (NumberFormatException localNumberFormatException)
  548. {
  549. JSONScanner localJSONScanner = new JSONScanner((String)localObject);
  550. localObject = null;
  551. if (localJSONScanner.scanISO8601DateIfMatch(false))
  552. localObject = localJSONScanner.getCalendar();
  553. localJSONScanner.close();
  554. if (localObject != null)
  555. return Long.valueOf(((Calendar)localObject).getTimeInMillis());
  556. }
  557. throw new JSONException("can not cast to long, value : " + paramObject);
  558. }
  559. public static final Short castToShort(Object paramObject)
  560. {
  561. if (paramObject == null);
  562. do
  563. {
  564. return null;
  565. if ((paramObject instanceof Number))
  566. return Short.valueOf(((Number)paramObject).shortValue());
  567. if (!(paramObject instanceof String))
  568. break;
  569. paramObject = (String)paramObject;
  570. }
  571. while (paramObject.length() == 0);
  572. return Short.valueOf(Short.parseShort(paramObject));
  573. throw new JSONException("can not cast to short, value : " + paramObject);
  574. }
  575. public static final java.sql.Date castToSqlDate(Object paramObject)
  576. {
  577. if (paramObject == null)
  578. return null;
  579. if ((paramObject instanceof Calendar))
  580. return new java.sql.Date(((Calendar)paramObject).getTimeInMillis());
  581. if ((paramObject instanceof java.sql.Date))
  582. return (java.sql.Date)paramObject;
  583. if ((paramObject instanceof java.util.Date))
  584. return new java.sql.Date(((java.util.Date)paramObject).getTime());
  585. long l = 0L;
  586. if ((paramObject instanceof Number))
  587. l = ((Number)paramObject).longValue();
  588. if ((paramObject instanceof String))
  589. {
  590. String str = (String)paramObject;
  591. if (str.length() == 0)
  592. return null;
  593. l = Long.parseLong(str);
  594. }
  595. if (l <= 0L)
  596. throw new JSONException("can not cast to Date, value : " + paramObject);
  597. return new java.sql.Date(l);
  598. }
  599. public static final String castToString(Object paramObject)
  600. {
  601. if (paramObject == null)
  602. return null;
  603. return paramObject.toString();
  604. }
  605. public static final Timestamp castToTimestamp(Object paramObject)
  606. {
  607. if (paramObject == null)
  608. return null;
  609. if ((paramObject instanceof Calendar))
  610. return new Timestamp(((Calendar)paramObject).getTimeInMillis());
  611. if ((paramObject instanceof Timestamp))
  612. return (Timestamp)paramObject;
  613. if ((paramObject instanceof java.util.Date))
  614. return new Timestamp(((java.util.Date)paramObject).getTime());
  615. long l = 0L;
  616. if ((paramObject instanceof Number))
  617. l = ((Number)paramObject).longValue();
  618. if ((paramObject instanceof String))
  619. {
  620. String str = (String)paramObject;
  621. if (str.length() == 0)
  622. return null;
  623. l = Long.parseLong(str);
  624. }
  625. if (l <= 0L)
  626. throw new JSONException("can not cast to Date, value : " + paramObject);
  627. return new Timestamp(l);
  628. }
  629. public static void clearClassMapping()
  630. {
  631. mappings.clear();
  632. addBaseClassMappings();
  633. }
  634. public static List<FieldInfo> computeGetters(Class<?> paramClass, Map<String, String> paramMap)
  635. {
  636. return computeGetters(paramClass, paramMap, true);
  637. }
  638. public static List<FieldInfo> computeGetters(Class<?> paramClass, Map<String, String> paramMap, boolean paramBoolean)
  639. {
  640. LinkedHashMap localLinkedHashMap = new LinkedHashMap();
  641. Method[] arrayOfMethod = paramClass.getMethods();
  642. int j = arrayOfMethod.length;
  643. int i = 0;
  644. Object localObject4;
  645. if (i < j)
  646. {
  647. localObject4 = arrayOfMethod[i];
  648. Object localObject5 = ((Method)localObject4).getName();
  649. if (Modifier.isStatic(((Method)localObject4).getModifiers()));
  650. label247:
  651. do
  652. {
  653. do
  654. {
  655. do
  656. {
  657. JSONField localJSONField;
  658. do
  659. {
  660. do
  661. {
  662. while (true)
  663. {
  664. i += 1;
  665. break;
  666. if ((!((Method)localObject4).getReturnType().equals(Void.TYPE)) && (((Method)localObject4).getParameterTypes().length == 0) && (((Method)localObject4).getReturnType() != ClassLoader.class) && ((!((Method)localObject4).getName().equals("getMetaClass")) || (!((Method)localObject4).getReturnType().getName().equals("groovy.lang.MetaClass"))))
  667. {
  668. localObject2 = (JSONField)((Method)localObject4).getAnnotation(JSONField.class);
  669. localObject1 = localObject2;
  670. if (localObject2 == null)
  671. localObject1 = getSupperMethodAnnotation(paramClass, (Method)localObject4);
  672. if (localObject1 == null)
  673. break label247;
  674. if (((JSONField)localObject1).serialize())
  675. {
  676. if (((JSONField)localObject1).name().length() == 0)
  677. break label247;
  678. localObject2 = ((JSONField)localObject1).name();
  679. localObject1 = localObject2;
  680. if (paramMap != null)
  681. {
  682. localObject1 = (String)paramMap.get(localObject2);
  683. if (localObject1 == null);
  684. }
  685. else
  686. {
  687. localLinkedHashMap.put(localObject1, new FieldInfo((String)localObject1, (Method)localObject4, null));
  688. }
  689. }
  690. }
  691. }
  692. if (!((String)localObject5).startsWith("get"))
  693. break label468;
  694. }
  695. while ((((String)localObject5).length() < 4) || (((String)localObject5).equals("getClass")));
  696. c = ((String)localObject5).charAt(3);
  697. if (!Character.isUpperCase(c))
  698. break label725;
  699. if (!compatibleWithJavaBean)
  700. break label689;
  701. localObject1 = Introspector.decapitalize(((String)localObject5).substring(3));
  702. if (isJSONTypeIgnore(paramClass, (String)localObject1))
  703. break label757;
  704. localObject3 = ParserConfig.getField(paramClass, (String)localObject1);
  705. localObject2 = localObject1;
  706. if (localObject3 == null)
  707. break label419;
  708. localJSONField = (JSONField)((Field)localObject3).getAnnotation(JSONField.class);
  709. localObject2 = localObject1;
  710. if (localJSONField == null)
  711. break label419;
  712. }
  713. while (!localJSONField.serialize());
  714. localObject2 = localObject1;
  715. if (localJSONField.name().length() == 0)
  716. break label419;
  717. localObject1 = localJSONField.name();
  718. localObject2 = localObject1;
  719. if (paramMap == null)
  720. break label419;
  721. localObject2 = (String)paramMap.get(localObject1);
  722. }
  723. while (localObject2 == null);
  724. localObject1 = localObject2;
  725. if (paramMap == null)
  726. break label445;
  727. localObject1 = (String)paramMap.get(localObject2);
  728. }
  729. while (localObject1 == null);
  730. localLinkedHashMap.put(localObject1, new FieldInfo((String)localObject1, (Method)localObject4, (Field)localObject3));
  731. }
  732. while ((!((String)localObject5).startsWith("is")) || (((String)localObject5).length() < 3));
  733. label309: label445: label468: char c = ((String)localObject5).charAt(2);
  734. label419: if (Character.isUpperCase(c))
  735. if (compatibleWithJavaBean)
  736. localObject1 = Introspector.decapitalize(((String)localObject5).substring(2));
  737. while (true)
  738. {
  739. localObject2 = ParserConfig.getField(paramClass, (String)localObject1);
  740. localObject3 = localObject2;
  741. if (localObject2 == null)
  742. localObject3 = ParserConfig.getField(paramClass, (String)localObject5);
  743. localObject2 = localObject1;
  744. if (localObject3 != null)
  745. {
  746. localObject5 = (JSONField)((Field)localObject3).getAnnotation(JSONField.class);
  747. localObject2 = localObject1;
  748. if (localObject5 != null)
  749. {
  750. if (!((JSONField)localObject5).serialize())
  751. break;
  752. localObject2 = localObject1;
  753. if (((JSONField)localObject5).name().length() != 0)
  754. {
  755. localObject1 = ((JSONField)localObject5).name();
  756. localObject2 = localObject1;
  757. if (paramMap != null)
  758. {
  759. localObject2 = (String)paramMap.get(localObject1);
  760. if (localObject2 == null)
  761. break;
  762. }
  763. }
  764. }
  765. }
  766. localObject1 = localObject2;
  767. if (paramMap != null)
  768. {
  769. localObject1 = (String)paramMap.get(localObject2);
  770. if (localObject1 == null)
  771. break;
  772. }
  773. localLinkedHashMap.put(localObject1, new FieldInfo((String)localObject1, (Method)localObject4, (Field)localObject3));
  774. break;
  775. label689: localObject1 = Character.toLowerCase(((String)localObject5).charAt(3)) + ((String)localObject5).substring(4);
  776. break label309;
  777. label725: if (c == '_')
  778. {
  779. localObject1 = ((String)localObject5).substring(4);
  780. break label309;
  781. }
  782. if (c != 'f')
  783. break;
  784. localObject1 = ((String)localObject5).substring(3);
  785. break label309;
  786. label757: break;
  787. localObject1 = Character.toLowerCase(((String)localObject5).charAt(2)) + ((String)localObject5).substring(3);
  788. continue;
  789. if (c == '_')
  790. {
  791. localObject1 = ((String)localObject5).substring(3);
  792. }
  793. else
  794. {
  795. if (c != 'f')
  796. break;
  797. localObject1 = ((String)localObject5).substring(2);
  798. }
  799. }
  800. }
  801. Object localObject3 = paramClass.getFields();
  802. j = localObject3.length;
  803. i = 0;
  804. if (i < j)
  805. {
  806. arrayOfMethod = localObject3[i];
  807. if (Modifier.isStatic(arrayOfMethod.getModifiers()));
  808. while (true)
  809. {
  810. i += 1;
  811. break;
  812. localObject4 = (JSONField)arrayOfMethod.getAnnotation(JSONField.class);
  813. localObject2 = arrayOfMethod.getName();
  814. localObject1 = localObject2;
  815. if (localObject4 != null)
  816. {
  817. if (((JSONField)localObject4).serialize())
  818. {
  819. localObject1 = localObject2;
  820. if (((JSONField)localObject4).name().length() != 0)
  821. localObject1 = ((JSONField)localObject4).name();
  822. }
  823. }
  824. else
  825. {
  826. localObject2 = localObject1;
  827. if (paramMap != null)
  828. {
  829. localObject2 = (String)paramMap.get(localObject1);
  830. if (localObject2 == null);
  831. }
  832. else if (!localLinkedHashMap.containsKey(localObject2))
  833. {
  834. localLinkedHashMap.put(localObject2, new FieldInfo((String)localObject2, null, arrayOfMethod));
  835. }
  836. }
  837. }
  838. }
  839. Object localObject1 = new ArrayList();
  840. i = 0;
  841. paramMap = null;
  842. Object localObject2 = (JSONType)paramClass.getAnnotation(JSONType.class);
  843. paramClass = paramMap;
  844. if (localObject2 != null)
  845. {
  846. paramMap = ((JSONType)localObject2).orders();
  847. if ((paramMap == null) || (paramMap.length != localLinkedHashMap.size()))
  848. break label1163;
  849. int k = 1;
  850. int m = paramMap.length;
  851. j = 0;
  852. i = k;
  853. paramClass = paramMap;
  854. if (j < m)
  855. {
  856. if (localLinkedHashMap.containsKey(paramMap[j]))
  857. break label1154;
  858. i = 0;
  859. }
  860. }
  861. for (paramClass = paramMap; ; paramClass = paramMap)
  862. {
  863. if (i == 0)
  864. break label1171;
  865. j = paramClass.length;
  866. i = 0;
  867. while (i < j)
  868. {
  869. ((List)localObject1).add((FieldInfo)localLinkedHashMap.get(paramClass[i]));
  870. i += 1;
  871. }
  872. label1154: j += 1;
  873. break;
  874. label1163: i = 0;
  875. }
  876. label1171: paramClass = localLinkedHashMap.values().iterator();
  877. while (paramClass.hasNext())
  878. ((List)localObject1).add((FieldInfo)paramClass.next());
  879. if (paramBoolean)
  880. Collections.sort((List)localObject1);
  881. return localObject1;
  882. }
  883. public static Class<?> getClass(Type paramType)
  884. {
  885. if (paramType.getClass() == Class.class)
  886. return (Class)paramType;
  887. if ((paramType instanceof ParameterizedType))
  888. return getClass(((ParameterizedType)paramType).getRawType());
  889. return Object.class;
  890. }
  891. public static JSONField getSupperMethodAnnotation(Class<?> paramClass, Method paramMethod)
  892. {
  893. paramClass = paramClass.getInterfaces();
  894. int i1 = paramClass.length;
  895. int i = 0;
  896. while (i < i1)
  897. {
  898. Method[] arrayOfMethod = paramClass[i].getMethods();
  899. int i2 = arrayOfMethod.length;
  900. int j = 0;
  901. if (j < i2)
  902. {
  903. Object localObject = arrayOfMethod[j];
  904. if (!((Method)localObject).getName().equals(paramMethod.getName()));
  905. while (((Method)localObject).getParameterTypes().length != paramMethod.getParameterTypes().length)
  906. {
  907. j += 1;
  908. break;
  909. }
  910. int n = 1;
  911. int k = 0;
  912. while (true)
  913. {
  914. int m = n;
  915. if (k < ((Method)localObject).getParameterTypes().length)
  916. {
  917. if (!localObject.getParameterTypes()[k].equals(paramMethod.getParameterTypes()[k]))
  918. m = 0;
  919. }
  920. else
  921. {
  922. if (m == 0)
  923. break;
  924. localObject = (JSONField)((Method)localObject).getAnnotation(JSONField.class);
  925. if (localObject == null)
  926. break;
  927. return localObject;
  928. }
  929. k += 1;
  930. }
  931. }
  932. i += 1;
  933. }
  934. return null;
  935. }
  936. private static boolean isJSONTypeIgnore(Class<?> paramClass, String paramString)
  937. {
  938. Object localObject = (JSONType)paramClass.getAnnotation(JSONType.class);
  939. int i;
  940. if ((localObject != null) && (((JSONType)localObject).ignores() != null))
  941. {
  942. localObject = ((JSONType)localObject).ignores();
  943. int j = localObject.length;
  944. i = 0;
  945. if (i < j)
  946. if (!paramString.equalsIgnoreCase(localObject[i]));
  947. }
  948. while ((paramClass.getSuperclass() != Object.class) && (paramClass.getSuperclass() != null) && (isJSONTypeIgnore(paramClass.getSuperclass(), paramString)))
  949. {
  950. return true;
  951. i += 1;
  952. break;
  953. }
  954. return false;
  955. }
  956. public static Class<?> loadClass(String paramString)
  957. {
  958. if ((paramString == null) || (paramString.length() == 0))
  959. localObject = null;
  960. Class localClass1;
  961. do
  962. {
  963. return localObject;
  964. localClass1 = (Class)mappings.get(paramString);
  965. localObject = localClass1;
  966. }
  967. while (localClass1 != null);
  968. if (paramString.charAt(0) == '[')
  969. return Array.newInstance(loadClass(paramString.substring(1)), 0).getClass();
  970. if ((paramString.startsWith("L")) && (paramString.endsWith(";")))
  971. return loadClass(paramString.substring(1, paramString.length() - 1));
  972. Object localObject = localClass1;
  973. try
  974. {
  975. ClassLoader localClassLoader = Thread.currentThread().getContextClassLoader();
  976. localObject = localClass1;
  977. if (localClassLoader != null)
  978. {
  979. localObject = localClass1;
  980. localClass1 = localClassLoader.loadClass(paramString);
  981. localObject = localClass1;
  982. addClassMapping(paramString, localClass1);
  983. return localClass1;
  984. }
  985. }
  986. catch (Throwable localThrowable)
  987. {
  988. try
  989. {
  990. Class localClass2 = Class.forName(paramString);
  991. localObject = localClass2;
  992. addClassMapping(paramString, localClass2);
  993. return localClass2;
  994. }
  995. catch (Throwable paramString)
  996. {
  997. }
  998. }
  999. return localObject;
  1000. }
  1001. }
  1002. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  1003. * Qualified Name: com.alibaba.fastjson.util.TypeUtils
  1004. * JD-Core Version: 0.6.2
  1005. */