PageRenderTime 62ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/QingTingFanBianYi/src/com/alibaba/fastjson/parser/DefaultJSONParser.java

https://gitlab.com/qt-prometheus/qt-prometheus
Java | 1380 lines | 1306 code | 70 blank | 4 comment | 279 complexity | 1d6ba5cd115f3a212bcbf2fa15c38be5 MD5 | raw file
  1. package com.alibaba.fastjson.parser;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONException;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer;
  7. import com.alibaba.fastjson.parser.deserializer.CollectionResolveFieldDeserializer;
  8. import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
  9. import com.alibaba.fastjson.parser.deserializer.ExtraTypeProvider;
  10. import com.alibaba.fastjson.parser.deserializer.FieldDeserializer;
  11. import com.alibaba.fastjson.parser.deserializer.IntegerDeserializer;
  12. import com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer;
  13. import com.alibaba.fastjson.parser.deserializer.ListResolveFieldDeserializer;
  14. import com.alibaba.fastjson.parser.deserializer.LongDeserializer;
  15. import com.alibaba.fastjson.parser.deserializer.MapResolveFieldDeserializer;
  16. import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
  17. import com.alibaba.fastjson.parser.deserializer.StringDeserializer;
  18. import com.alibaba.fastjson.util.TypeUtils;
  19. import java.io.Closeable;
  20. import java.lang.reflect.ParameterizedType;
  21. import java.lang.reflect.Type;
  22. import java.lang.reflect.TypeVariable;
  23. import java.lang.reflect.WildcardType;
  24. import java.math.BigDecimal;
  25. import java.math.BigInteger;
  26. import java.text.DateFormat;
  27. import java.text.SimpleDateFormat;
  28. import java.util.ArrayList;
  29. import java.util.Calendar;
  30. import java.util.Collection;
  31. import java.util.Date;
  32. import java.util.HashMap;
  33. import java.util.HashSet;
  34. import java.util.List;
  35. import java.util.Map;
  36. import java.util.Set;
  37. import java.util.TreeSet;
  38. public class DefaultJSONParser extends AbstractJSONParser
  39. implements Closeable
  40. {
  41. public static final int NONE = 0;
  42. public static final int NeedToResolve = 1;
  43. public static final int TypeNameRedirect = 2;
  44. private static final Set<Class<?>> primitiveClasses = new HashSet();
  45. protected ParserConfig config;
  46. protected ParseContext context;
  47. private ParseContext[] contextArray = new ParseContext[8];
  48. private int contextArrayIndex = 0;
  49. private DateFormat dateFormat;
  50. private String dateFormatPattern = JSON.DEFFAULT_DATE_FORMAT;
  51. private List<ExtraProcessor> extraProcessors = null;
  52. private List<ExtraTypeProvider> extraTypeProviders = null;
  53. protected final Object input;
  54. protected final JSONLexer lexer;
  55. private int resolveStatus = 0;
  56. private List<ResolveTask> resolveTaskList;
  57. protected final SymbolTable symbolTable;
  58. static
  59. {
  60. primitiveClasses.add(Boolean.TYPE);
  61. primitiveClasses.add(Byte.TYPE);
  62. primitiveClasses.add(Short.TYPE);
  63. primitiveClasses.add(Integer.TYPE);
  64. primitiveClasses.add(Long.TYPE);
  65. primitiveClasses.add(Float.TYPE);
  66. primitiveClasses.add(Double.TYPE);
  67. primitiveClasses.add(Boolean.class);
  68. primitiveClasses.add(Byte.class);
  69. primitiveClasses.add(Short.class);
  70. primitiveClasses.add(Integer.class);
  71. primitiveClasses.add(Long.class);
  72. primitiveClasses.add(Float.class);
  73. primitiveClasses.add(Double.class);
  74. primitiveClasses.add(BigInteger.class);
  75. primitiveClasses.add(BigDecimal.class);
  76. primitiveClasses.add(String.class);
  77. }
  78. public DefaultJSONParser(JSONLexer paramJSONLexer)
  79. {
  80. this(paramJSONLexer, ParserConfig.getGlobalInstance());
  81. }
  82. public DefaultJSONParser(JSONLexer paramJSONLexer, ParserConfig paramParserConfig)
  83. {
  84. this(null, paramJSONLexer, paramParserConfig);
  85. }
  86. public DefaultJSONParser(Object paramObject, JSONLexer paramJSONLexer, ParserConfig paramParserConfig)
  87. {
  88. this.lexer = paramJSONLexer;
  89. this.input = paramObject;
  90. this.config = paramParserConfig;
  91. this.symbolTable = paramParserConfig.getSymbolTable();
  92. paramJSONLexer.nextToken(12);
  93. }
  94. public DefaultJSONParser(String paramString)
  95. {
  96. this(paramString, ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
  97. }
  98. public DefaultJSONParser(String paramString, ParserConfig paramParserConfig)
  99. {
  100. this(paramString, new JSONScanner(paramString, JSON.DEFAULT_PARSER_FEATURE), paramParserConfig);
  101. }
  102. public DefaultJSONParser(String paramString, ParserConfig paramParserConfig, int paramInt)
  103. {
  104. this(paramString, new JSONScanner(paramString, paramInt), paramParserConfig);
  105. }
  106. public DefaultJSONParser(char[] paramArrayOfChar, int paramInt1, ParserConfig paramParserConfig, int paramInt2)
  107. {
  108. this(paramArrayOfChar, new JSONScanner(paramArrayOfChar, paramInt1, paramInt2), paramParserConfig);
  109. }
  110. private void addContext(ParseContext paramParseContext)
  111. {
  112. int i = this.contextArrayIndex;
  113. this.contextArrayIndex = (i + 1);
  114. if (i >= this.contextArray.length)
  115. {
  116. ParseContext[] arrayOfParseContext = new ParseContext[this.contextArray.length * 3 / 2];
  117. System.arraycopy(this.contextArray, 0, arrayOfParseContext, 0, this.contextArray.length);
  118. this.contextArray = arrayOfParseContext;
  119. }
  120. this.contextArray[i] = paramParseContext;
  121. }
  122. public final void accept(int paramInt)
  123. {
  124. JSONLexer localJSONLexer = getLexer();
  125. if (localJSONLexer.token() == paramInt)
  126. {
  127. localJSONLexer.nextToken();
  128. return;
  129. }
  130. throw new JSONException("syntax error, expect " + JSONToken.name(paramInt) + ", actual " + JSONToken.name(localJSONLexer.token()));
  131. }
  132. public final void accept(int paramInt1, int paramInt2)
  133. {
  134. JSONLexer localJSONLexer = getLexer();
  135. if (localJSONLexer.token() == paramInt1)
  136. {
  137. localJSONLexer.nextToken(paramInt2);
  138. return;
  139. }
  140. throw new JSONException("syntax error, expect " + JSONToken.name(paramInt1) + ", actual " + JSONToken.name(localJSONLexer.token()));
  141. }
  142. public void acceptType(String paramString)
  143. {
  144. JSONLexer localJSONLexer = this.lexer;
  145. localJSONLexer.nextTokenWithColon();
  146. if (localJSONLexer.token() != 4)
  147. throw new JSONException("type not match error");
  148. if (paramString.equals(localJSONLexer.stringVal()))
  149. {
  150. localJSONLexer.nextToken();
  151. if (localJSONLexer.token() == 16)
  152. localJSONLexer.nextToken();
  153. return;
  154. }
  155. throw new JSONException("type not match error");
  156. }
  157. public void addResolveTask(ResolveTask paramResolveTask)
  158. {
  159. if (this.resolveTaskList == null)
  160. this.resolveTaskList = new ArrayList(2);
  161. this.resolveTaskList.add(paramResolveTask);
  162. }
  163. public void checkListResolve(Collection paramCollection)
  164. {
  165. if (this.resolveStatus == 1)
  166. {
  167. if ((paramCollection instanceof List))
  168. {
  169. int i = paramCollection.size();
  170. paramCollection = (List)paramCollection;
  171. localResolveTask = getLastResolveTask();
  172. localResolveTask.setFieldDeserializer(new ListResolveFieldDeserializer(this, paramCollection, i - 1));
  173. localResolveTask.setOwnerContext(this.context);
  174. setResolveStatus(0);
  175. }
  176. }
  177. else
  178. return;
  179. ResolveTask localResolveTask = getLastResolveTask();
  180. localResolveTask.setFieldDeserializer(new CollectionResolveFieldDeserializer(this, paramCollection));
  181. localResolveTask.setOwnerContext(this.context);
  182. setResolveStatus(0);
  183. }
  184. public void checkMapResolve(Map paramMap, String paramString)
  185. {
  186. if (this.resolveStatus == 1)
  187. {
  188. paramMap = new MapResolveFieldDeserializer(paramMap, paramString);
  189. paramString = getLastResolveTask();
  190. paramString.setFieldDeserializer(paramMap);
  191. paramString.setOwnerContext(this.context);
  192. setResolveStatus(0);
  193. }
  194. }
  195. public void close()
  196. {
  197. JSONLexer localJSONLexer = getLexer();
  198. try
  199. {
  200. if ((isEnabled(Feature.AutoCloseSource)) && (localJSONLexer.token() != 20))
  201. throw new JSONException("not close json text, token : " + JSONToken.name(localJSONLexer.token()));
  202. }
  203. finally
  204. {
  205. localJSONLexer.close();
  206. }
  207. localJSONLexer.close();
  208. }
  209. public void config(Feature paramFeature, boolean paramBoolean)
  210. {
  211. getLexer().config(paramFeature, paramBoolean);
  212. }
  213. public ParserConfig getConfig()
  214. {
  215. return this.config;
  216. }
  217. public ParseContext getContext()
  218. {
  219. return this.context;
  220. }
  221. public String getDateFomartPattern()
  222. {
  223. return this.dateFormatPattern;
  224. }
  225. public DateFormat getDateFormat()
  226. {
  227. if (this.dateFormat == null)
  228. this.dateFormat = new SimpleDateFormat(this.dateFormatPattern);
  229. return this.dateFormat;
  230. }
  231. public List<ExtraProcessor> getExtraProcessors()
  232. {
  233. if (this.extraProcessors == null)
  234. this.extraProcessors = new ArrayList(2);
  235. return this.extraProcessors;
  236. }
  237. public List<ExtraProcessor> getExtraProcessorsDirect()
  238. {
  239. return this.extraProcessors;
  240. }
  241. public List<ExtraTypeProvider> getExtraTypeProviders()
  242. {
  243. if (this.extraTypeProviders == null)
  244. this.extraTypeProviders = new ArrayList(2);
  245. return this.extraTypeProviders;
  246. }
  247. public List<ExtraTypeProvider> getExtraTypeProvidersDirect()
  248. {
  249. return this.extraTypeProviders;
  250. }
  251. public String getInput()
  252. {
  253. if ((this.input instanceof char[]))
  254. return new String((char[])this.input);
  255. return this.input.toString();
  256. }
  257. public ResolveTask getLastResolveTask()
  258. {
  259. return (ResolveTask)this.resolveTaskList.get(this.resolveTaskList.size() - 1);
  260. }
  261. public JSONLexer getLexer()
  262. {
  263. return this.lexer;
  264. }
  265. public Object getObject(String paramString)
  266. {
  267. int i = 0;
  268. while (i < this.contextArrayIndex)
  269. {
  270. if (paramString.equals(this.contextArray[i].getPath()))
  271. return this.contextArray[i].getObject();
  272. i += 1;
  273. }
  274. return null;
  275. }
  276. public int getResolveStatus()
  277. {
  278. return this.resolveStatus;
  279. }
  280. public List<ResolveTask> getResolveTaskList()
  281. {
  282. if (this.resolveTaskList == null)
  283. this.resolveTaskList = new ArrayList(2);
  284. return this.resolveTaskList;
  285. }
  286. public List<ResolveTask> getResolveTaskListDirect()
  287. {
  288. return this.resolveTaskList;
  289. }
  290. public SymbolTable getSymbolTable()
  291. {
  292. return this.symbolTable;
  293. }
  294. public boolean isEnabled(Feature paramFeature)
  295. {
  296. return getLexer().isEnabled(paramFeature);
  297. }
  298. public Object parse()
  299. {
  300. return parse(null);
  301. }
  302. public Object parse(Object paramObject)
  303. {
  304. Object localObject1 = null;
  305. JSONLexer localJSONLexer = getLexer();
  306. switch (localJSONLexer.token())
  307. {
  308. case 5:
  309. case 10:
  310. case 11:
  311. case 13:
  312. case 15:
  313. case 16:
  314. case 17:
  315. case 18:
  316. case 19:
  317. default:
  318. throw new JSONException("syntax error, pos " + localJSONLexer.getBufferPosition());
  319. case 21:
  320. localJSONLexer.nextToken();
  321. localObject1 = new HashSet();
  322. parseArray((Collection)localObject1, paramObject);
  323. paramObject = localObject1;
  324. case 22:
  325. case 14:
  326. case 12:
  327. case 2:
  328. case 3:
  329. case 4:
  330. case 8:
  331. case 6:
  332. case 7:
  333. case 9:
  334. case 20:
  335. }
  336. do
  337. {
  338. return paramObject;
  339. localJSONLexer.nextToken();
  340. localObject1 = new TreeSet();
  341. parseArray((Collection)localObject1, paramObject);
  342. return localObject1;
  343. localObject1 = new JSONArray();
  344. parseArray((Collection)localObject1, paramObject);
  345. return localObject1;
  346. return parseObject(new JSONObject(), paramObject);
  347. paramObject = localJSONLexer.integerValue();
  348. localJSONLexer.nextToken();
  349. return paramObject;
  350. paramObject = localJSONLexer.decimalValue(isEnabled(Feature.UseBigDecimal));
  351. localJSONLexer.nextToken();
  352. return paramObject;
  353. localObject1 = localJSONLexer.stringVal();
  354. localJSONLexer.nextToken(16);
  355. if (localJSONLexer.isEnabled(Feature.AllowISO8601DateFormat))
  356. paramObject = new JSONScanner((String)localObject1);
  357. try
  358. {
  359. if (paramObject.scanISO8601DateIfMatch())
  360. {
  361. localObject1 = paramObject.getCalendar().getTime();
  362. return localObject1;
  363. }
  364. return localObject1;
  365. }
  366. finally
  367. {
  368. paramObject.close();
  369. }
  370. localJSONLexer.nextToken();
  371. return null;
  372. localJSONLexer.nextToken();
  373. return Boolean.TRUE;
  374. localJSONLexer.nextToken();
  375. return Boolean.FALSE;
  376. localJSONLexer.nextToken(18);
  377. if (localJSONLexer.token() != 18)
  378. throw new JSONException("syntax error");
  379. localJSONLexer.nextToken(10);
  380. accept(10);
  381. long l = localJSONLexer.integerValue().longValue();
  382. accept(2);
  383. accept(11);
  384. return new Date(l);
  385. paramObject = localObject2;
  386. }
  387. while (localJSONLexer.isBlankInput());
  388. throw new JSONException("unterminated json string, pos " + localJSONLexer.getBufferPosition());
  389. }
  390. public <T> List<T> parseArray(Class<T> paramClass)
  391. {
  392. ArrayList localArrayList = new ArrayList();
  393. parseArray(paramClass, localArrayList);
  394. return localArrayList;
  395. }
  396. public void parseArray(Class<?> paramClass, Collection paramCollection)
  397. {
  398. parseArray(paramClass, paramCollection);
  399. }
  400. public void parseArray(Type paramType, Collection paramCollection)
  401. {
  402. parseArray(paramType, paramCollection, null);
  403. }
  404. public void parseArray(Type paramType, Collection paramCollection, Object paramObject)
  405. {
  406. if ((this.lexer.token() == 21) || (this.lexer.token() == 22))
  407. this.lexer.nextToken();
  408. if (this.lexer.token() != 14)
  409. throw new JSONException("exepct '[', but " + JSONToken.name(this.lexer.token()));
  410. Object localObject;
  411. ParseContext localParseContext;
  412. int i;
  413. if (Integer.TYPE == paramType)
  414. {
  415. localObject = IntegerDeserializer.instance;
  416. this.lexer.nextToken(2);
  417. localParseContext = getContext();
  418. setContext(paramCollection, paramObject);
  419. i = 0;
  420. }
  421. while (true)
  422. {
  423. try
  424. {
  425. if (!isEnabled(Feature.AllowArbitraryCommas))
  426. break label226;
  427. if (this.lexer.token() != 16)
  428. break label226;
  429. this.lexer.nextToken();
  430. continue;
  431. }
  432. finally
  433. {
  434. setContext(localParseContext);
  435. }
  436. if (String.class == paramType)
  437. {
  438. localObject = StringDeserializer.instance;
  439. this.lexer.nextToken(4);
  440. break;
  441. }
  442. localObject = this.config.getDeserializer(paramType);
  443. this.lexer.nextToken(((ObjectDeserializer)localObject).getFastMatchToken());
  444. break;
  445. label226: int j = this.lexer.token();
  446. if (j == 15)
  447. {
  448. setContext(localParseContext);
  449. this.lexer.nextToken(16);
  450. return;
  451. }
  452. if (Integer.TYPE == paramType)
  453. {
  454. paramCollection.add(IntegerDeserializer.instance.deserialze(this, null, null));
  455. if (this.lexer.token() == 16)
  456. this.lexer.nextToken(((ObjectDeserializer)localObject).getFastMatchToken());
  457. }
  458. else
  459. {
  460. if (String.class == paramType)
  461. {
  462. if (this.lexer.token() == 4)
  463. {
  464. paramObject = this.lexer.stringVal();
  465. this.lexer.nextToken(16);
  466. }
  467. while (true)
  468. {
  469. paramCollection.add(paramObject);
  470. break;
  471. paramObject = parse();
  472. if (paramObject == null)
  473. paramObject = null;
  474. else
  475. paramObject = paramObject.toString();
  476. }
  477. }
  478. if (this.lexer.token() == 8)
  479. this.lexer.nextToken();
  480. for (paramObject = null; ; paramObject = ((ObjectDeserializer)localObject).deserialze(this, paramType, Integer.valueOf(i)))
  481. {
  482. paramCollection.add(paramObject);
  483. checkListResolve(paramCollection);
  484. break;
  485. }
  486. }
  487. i += 1;
  488. }
  489. }
  490. public final void parseArray(Collection paramCollection)
  491. {
  492. parseArray(paramCollection, null);
  493. }
  494. public final void parseArray(Collection paramCollection, Object paramObject)
  495. {
  496. JSONLexer localJSONLexer = getLexer();
  497. if ((localJSONLexer.token() == 21) || (localJSONLexer.token() == 22))
  498. localJSONLexer.nextToken();
  499. if (localJSONLexer.token() != 14)
  500. throw new JSONException("syntax error, expect [, actual " + JSONToken.name(localJSONLexer.token()) + ", pos " + localJSONLexer.pos());
  501. localJSONLexer.nextToken(4);
  502. ParseContext localParseContext = getContext();
  503. setContext(paramCollection, paramObject);
  504. int i = 0;
  505. try
  506. {
  507. if (isEnabled(Feature.AllowArbitraryCommas))
  508. while (localJSONLexer.token() == 16)
  509. localJSONLexer.nextToken();
  510. }
  511. finally
  512. {
  513. setContext(localParseContext);
  514. }
  515. switch (localJSONLexer.token())
  516. {
  517. case 5:
  518. case 9:
  519. case 10:
  520. case 11:
  521. case 13:
  522. case 16:
  523. case 17:
  524. case 18:
  525. case 19:
  526. label264: paramObject = parse();
  527. case 2:
  528. case 3:
  529. case 4:
  530. case 6:
  531. case 7:
  532. case 12:
  533. case 14:
  534. case 8:
  535. case 15:
  536. case 20:
  537. }
  538. while (true)
  539. {
  540. label269: paramCollection.add(paramObject);
  541. checkListResolve(paramCollection);
  542. JSONScanner localJSONScanner;
  543. if (localJSONLexer.token() == 16)
  544. {
  545. localJSONLexer.nextToken(4);
  546. break label551;
  547. paramObject = localJSONLexer.integerValue();
  548. localJSONLexer.nextToken(16);
  549. continue;
  550. if (localJSONLexer.isEnabled(Feature.UseBigDecimal));
  551. for (paramObject = localJSONLexer.decimalValue(true); ; paramObject = localJSONLexer.decimalValue(false))
  552. {
  553. localJSONLexer.nextToken(16);
  554. break;
  555. }
  556. paramObject = localJSONLexer.stringVal();
  557. localJSONLexer.nextToken(16);
  558. if (localJSONLexer.isEnabled(Feature.AllowISO8601DateFormat))
  559. {
  560. localJSONScanner = new JSONScanner(paramObject);
  561. if (localJSONScanner.scanISO8601DateIfMatch())
  562. paramObject = localJSONScanner.getCalendar().getTime();
  563. }
  564. }
  565. else
  566. {
  567. while (true)
  568. {
  569. localJSONScanner.close();
  570. break label269;
  571. paramObject = Boolean.TRUE;
  572. localJSONLexer.nextToken(16);
  573. break label269;
  574. paramObject = Boolean.FALSE;
  575. localJSONLexer.nextToken(16);
  576. break label269;
  577. paramObject = parseObject(new JSONObject(), Integer.valueOf(i));
  578. break label269;
  579. paramObject = new JSONArray();
  580. parseArray(paramObject, Integer.valueOf(i));
  581. break label269;
  582. paramObject = null;
  583. localJSONLexer.nextToken(4);
  584. break label269;
  585. localJSONLexer.nextToken(16);
  586. setContext(localParseContext);
  587. return;
  588. throw new JSONException("unclosed jsonArray");
  589. break label264;
  590. label551: i += 1;
  591. break;
  592. }
  593. }
  594. }
  595. }
  596. public Object[] parseArray(Type[] paramArrayOfType)
  597. {
  598. if (this.lexer.token() == 8)
  599. {
  600. this.lexer.nextToken(16);
  601. return null;
  602. }
  603. if (this.lexer.token() != 14)
  604. throw new JSONException("syntax error : " + this.lexer.tokenName());
  605. Object[] arrayOfObject = new Object[paramArrayOfType.length];
  606. if (paramArrayOfType.length == 0)
  607. {
  608. this.lexer.nextToken(15);
  609. if (this.lexer.token() != 15)
  610. throw new JSONException("syntax error");
  611. this.lexer.nextToken(16);
  612. return new Object[0];
  613. }
  614. this.lexer.nextToken(2);
  615. int i = 0;
  616. Object localObject;
  617. if (i < paramArrayOfType.length)
  618. {
  619. if (this.lexer.token() != 8)
  620. break label233;
  621. localObject = null;
  622. this.lexer.nextToken(16);
  623. }
  624. while (true)
  625. {
  626. arrayOfObject[i] = localObject;
  627. if (this.lexer.token() != 15)
  628. break;
  629. if (this.lexer.token() == 15)
  630. break label710;
  631. throw new JSONException("syntax error");
  632. label233: Type localType = paramArrayOfType[i];
  633. if ((localType == Integer.TYPE) || (localType == Integer.class))
  634. {
  635. if (this.lexer.token() == 2)
  636. {
  637. localObject = Integer.valueOf(this.lexer.intValue());
  638. this.lexer.nextToken(16);
  639. }
  640. else
  641. {
  642. localObject = TypeUtils.cast(parse(), localType, this.config);
  643. }
  644. }
  645. else if (localType == String.class)
  646. {
  647. if (this.lexer.token() == 4)
  648. {
  649. localObject = this.lexer.stringVal();
  650. this.lexer.nextToken(16);
  651. }
  652. else
  653. {
  654. localObject = TypeUtils.cast(parse(), localType, this.config);
  655. }
  656. }
  657. else
  658. {
  659. boolean bool2 = false;
  660. ArrayList localArrayList = null;
  661. localObject = localArrayList;
  662. boolean bool1 = bool2;
  663. if (i == paramArrayOfType.length - 1)
  664. {
  665. localObject = localArrayList;
  666. bool1 = bool2;
  667. if ((localType instanceof Class))
  668. {
  669. localObject = (Class)localType;
  670. bool1 = ((Class)localObject).isArray();
  671. localObject = ((Class)localObject).getComponentType();
  672. }
  673. }
  674. if ((bool1) && (this.lexer.token() != 14))
  675. {
  676. localArrayList = new ArrayList();
  677. localObject = this.config.getDeserializer((Type)localObject);
  678. int j = ((ObjectDeserializer)localObject).getFastMatchToken();
  679. if (this.lexer.token() != 15)
  680. {
  681. while (true)
  682. {
  683. localArrayList.add(((ObjectDeserializer)localObject).deserialze(this, localType, null));
  684. if (this.lexer.token() != 16)
  685. break;
  686. this.lexer.nextToken(j);
  687. }
  688. if (this.lexer.token() != 15);
  689. }
  690. else
  691. {
  692. localObject = TypeUtils.cast(localArrayList, localType, this.config);
  693. continue;
  694. }
  695. throw new JSONException("syntax error :" + JSONToken.name(this.lexer.token()));
  696. }
  697. else
  698. {
  699. localObject = this.config.getDeserializer(localType).deserialze(this, localType, null);
  700. }
  701. }
  702. }
  703. if (this.lexer.token() != 16)
  704. throw new JSONException("syntax error :" + JSONToken.name(this.lexer.token()));
  705. if (i == paramArrayOfType.length - 1)
  706. this.lexer.nextToken(15);
  707. while (true)
  708. {
  709. i += 1;
  710. break;
  711. this.lexer.nextToken(2);
  712. }
  713. label710: this.lexer.nextToken(16);
  714. return arrayOfObject;
  715. }
  716. public Object parseArrayWithType(Type paramType)
  717. {
  718. if (this.lexer.token() == 8)
  719. {
  720. this.lexer.nextToken();
  721. return null;
  722. }
  723. Object localObject1 = ((ParameterizedType)paramType).getActualTypeArguments();
  724. if (localObject1.length != 1)
  725. throw new JSONException("not support type " + paramType);
  726. localObject1 = localObject1[0];
  727. if ((localObject1 instanceof Class))
  728. {
  729. paramType = new ArrayList();
  730. parseArray((Class)localObject1, paramType);
  731. return paramType;
  732. }
  733. Object localObject2;
  734. if ((localObject1 instanceof WildcardType))
  735. {
  736. localObject2 = (WildcardType)localObject1;
  737. localObject1 = localObject2.getUpperBounds()[0];
  738. if (Object.class.equals(localObject1))
  739. {
  740. if (((WildcardType)localObject2).getLowerBounds().length == 0)
  741. return parse();
  742. throw new JSONException("not support type : " + paramType);
  743. }
  744. paramType = new ArrayList();
  745. parseArray((Class)localObject1, paramType);
  746. return paramType;
  747. }
  748. if ((localObject1 instanceof TypeVariable))
  749. {
  750. localObject2 = (TypeVariable)localObject1;
  751. Type[] arrayOfType = ((TypeVariable)localObject2).getBounds();
  752. if (arrayOfType.length != 1)
  753. throw new JSONException("not support : " + localObject2);
  754. localObject2 = arrayOfType[0];
  755. if ((localObject2 instanceof Class))
  756. {
  757. paramType = new ArrayList();
  758. parseArray((Class)localObject2, paramType);
  759. return paramType;
  760. }
  761. }
  762. if ((localObject1 instanceof ParameterizedType))
  763. {
  764. paramType = (ParameterizedType)localObject1;
  765. localObject1 = new ArrayList();
  766. parseArray(paramType, (Collection)localObject1);
  767. return localObject1;
  768. }
  769. throw new JSONException("TODO : " + paramType);
  770. }
  771. public Object parseKey()
  772. {
  773. if (this.lexer.token() == 18)
  774. {
  775. String str = this.lexer.stringVal();
  776. this.lexer.nextToken(16);
  777. return str;
  778. }
  779. return parse(null);
  780. }
  781. public JSONObject parseObject()
  782. {
  783. JSONObject localJSONObject = new JSONObject();
  784. parseObject(localJSONObject);
  785. return localJSONObject;
  786. }
  787. public <T> T parseObject(Class<T> paramClass)
  788. {
  789. return parseObject(paramClass);
  790. }
  791. public <T> T parseObject(Type paramType)
  792. {
  793. if (this.lexer.token() == 8)
  794. {
  795. this.lexer.nextToken();
  796. return null;
  797. }
  798. ObjectDeserializer localObjectDeserializer = this.config.getDeserializer(paramType);
  799. try
  800. {
  801. paramType = localObjectDeserializer.deserialze(this, paramType, null);
  802. return paramType;
  803. }
  804. catch (JSONException paramType)
  805. {
  806. throw paramType;
  807. }
  808. catch (Throwable paramType)
  809. {
  810. }
  811. throw new JSONException(paramType.getMessage(), paramType);
  812. }
  813. public Object parseObject(Map paramMap)
  814. {
  815. return parseObject(paramMap, null);
  816. }
  817. public final Object parseObject(Map paramMap, Object paramObject)
  818. {
  819. JSONLexer localJSONLexer = this.lexer;
  820. if ((localJSONLexer.token() != 12) && (localJSONLexer.token() != 16))
  821. throw new JSONException("syntax error, expect {, actual " + localJSONLexer.tokenName());
  822. ParseContext localParseContext = getContext();
  823. int j = 0;
  824. int i;
  825. int k;
  826. Object localObject2;
  827. Object localObject1;
  828. try
  829. {
  830. localJSONLexer.skipWhitespace();
  831. i = localJSONLexer.getCurrent();
  832. k = i;
  833. if (isEnabled(Feature.AllowArbitraryCommas))
  834. while (true)
  835. {
  836. k = i;
  837. if (i != 44)
  838. break;
  839. localJSONLexer.next();
  840. localJSONLexer.skipWhitespace();
  841. i = localJSONLexer.getCurrent();
  842. }
  843. i = 0;
  844. if (k == 34)
  845. {
  846. localObject2 = localJSONLexer.scanSymbol(this.symbolTable, '"');
  847. localJSONLexer.skipWhitespace();
  848. localObject1 = localObject2;
  849. if (localJSONLexer.getCurrent() == ':')
  850. break label536;
  851. throw new JSONException("expect ':' at " + localJSONLexer.pos() + ", name " + localObject2);
  852. }
  853. }
  854. finally
  855. {
  856. setContext(localParseContext);
  857. }
  858. if (k == 125)
  859. {
  860. localJSONLexer.next();
  861. localJSONLexer.resetStringPosition();
  862. localJSONLexer.nextToken();
  863. setContext(localParseContext);
  864. return paramMap;
  865. }
  866. if (k == 39)
  867. {
  868. if (!isEnabled(Feature.AllowSingleQuotes))
  869. throw new JSONException("syntax error");
  870. localObject1 = localJSONLexer.scanSymbol(this.symbolTable, '\'');
  871. localJSONLexer.skipWhitespace();
  872. if (localJSONLexer.getCurrent() != ':')
  873. throw new JSONException("expect ':' at " + localJSONLexer.pos());
  874. }
  875. else
  876. {
  877. if (k == 26)
  878. throw new JSONException("syntax error");
  879. if (k != 44)
  880. break label1956;
  881. throw new JSONException("syntax error");
  882. label412: localJSONLexer.resetStringPosition();
  883. localJSONLexer.scanNumber();
  884. if (localJSONLexer.token() == 2);
  885. for (localObject2 = localJSONLexer.integerValue(); ; localObject2 = localJSONLexer.decimalValue(true))
  886. {
  887. localObject1 = localObject2;
  888. if (localJSONLexer.getCurrent() == ':')
  889. break;
  890. throw new JSONException("expect ':' at " + localJSONLexer.pos() + ", name " + localObject2);
  891. }
  892. label520: localJSONLexer.nextToken();
  893. localObject1 = parse();
  894. i = 1;
  895. }
  896. label536: label622: char c;
  897. do
  898. {
  899. if (i == 0)
  900. {
  901. localJSONLexer.next();
  902. localJSONLexer.skipWhitespace();
  903. }
  904. k = localJSONLexer.getCurrent();
  905. localJSONLexer.resetStringPosition();
  906. if (localObject1 != JSON.DEFAULT_TYPE_KEY)
  907. break label903;
  908. localObject2 = localJSONLexer.scanSymbol(this.symbolTable, '"');
  909. localObject1 = TypeUtils.loadClass((String)localObject2);
  910. if (localObject1 != null)
  911. break label720;
  912. paramMap.put(JSON.DEFAULT_TYPE_KEY, localObject2);
  913. break;
  914. if (!isEnabled(Feature.AllowUnQuotedFieldNames))
  915. throw new JSONException("syntax error");
  916. localObject1 = localJSONLexer.scanSymbolUnQuoted(this.symbolTable);
  917. localJSONLexer.skipWhitespace();
  918. c = localJSONLexer.getCurrent();
  919. }
  920. while (c == ':');
  921. throw new JSONException("expect ':' at " + localJSONLexer.pos() + ", actual " + c);
  922. label720: localJSONLexer.nextToken(16);
  923. if (localJSONLexer.token() == 13)
  924. {
  925. localJSONLexer.nextToken(16);
  926. paramMap = null;
  927. try
  928. {
  929. paramObject = this.config.getDeserializer((Type)localObject1);
  930. if ((paramObject instanceof ASMJavaBeanDeserializer))
  931. {
  932. paramMap = ((ASMJavaBeanDeserializer)paramObject).createInstance(this, (Type)localObject1);
  933. paramObject = paramMap;
  934. if (paramMap == null)
  935. if (localObject1 != Cloneable.class)
  936. break label831;
  937. }
  938. label831: for (paramObject = new HashMap(); ; paramObject = ((Class)localObject1).newInstance())
  939. {
  940. setContext(localParseContext);
  941. return paramObject;
  942. if (!(paramObject instanceof JavaBeanDeserializer))
  943. break;
  944. paramMap = ((JavaBeanDeserializer)paramObject).createInstance(this, (Type)localObject1);
  945. break;
  946. }
  947. }
  948. catch (Exception paramMap)
  949. {
  950. throw new JSONException("create instance error", paramMap);
  951. }
  952. }
  953. setResolveStatus(2);
  954. if ((this.context != null) && (!(paramObject instanceof Integer)))
  955. popContext();
  956. paramMap = this.config.getDeserializer((Type)localObject1).deserialze(this, (Type)localObject1, paramObject);
  957. setContext(localParseContext);
  958. return paramMap;
  959. label903: label978: Object localObject3;
  960. if (localObject1 == "$ref")
  961. {
  962. localJSONLexer.nextToken(4);
  963. if (localJSONLexer.token() == 4)
  964. {
  965. localObject1 = localJSONLexer.stringVal();
  966. localJSONLexer.nextToken(13);
  967. paramObject = null;
  968. paramMap = null;
  969. if ("@".equals(localObject1))
  970. {
  971. if (getContext() == null)
  972. break label2003;
  973. paramMap = getContext().getObject();
  974. if (localJSONLexer.token() != 13)
  975. throw new JSONException("syntax error");
  976. }
  977. else
  978. {
  979. if ("..".equals(localObject1))
  980. {
  981. paramObject = localParseContext.getParentContext();
  982. if (paramObject.getObject() != null)
  983. {
  984. paramMap = paramObject.getObject();
  985. break label1997;
  986. }
  987. addResolveTask(new ResolveTask(paramObject, (String)localObject1));
  988. setResolveStatus(1);
  989. break label1997;
  990. }
  991. if ("$".equals(localObject1))
  992. {
  993. for (paramMap = localParseContext; paramMap.getParentContext() != null; paramMap = paramMap.getParentContext());
  994. if (paramMap.getObject() != null)
  995. {
  996. paramMap = paramMap.getObject();
  997. break label2000;
  998. }
  999. addResolveTask(new ResolveTask(paramMap, (String)localObject1));
  1000. setResolveStatus(1);
  1001. paramMap = paramObject;
  1002. break label2000;
  1003. }
  1004. addResolveTask(new ResolveTask(localParseContext, (String)localObject1));
  1005. setResolveStatus(1);
  1006. break label2003;
  1007. }
  1008. localJSONLexer.nextToken(16);
  1009. setContext(localParseContext);
  1010. return paramMap;
  1011. }
  1012. else
  1013. {
  1014. throw new JSONException("illegal ref, " + JSONToken.name(localJSONLexer.token()));
  1015. }
  1016. }
  1017. else
  1018. {
  1019. i = j;
  1020. if (j == 0)
  1021. {
  1022. setContext(paramMap, paramObject);
  1023. j = 1;
  1024. i = j;
  1025. if (this.context != null)
  1026. {
  1027. i = j;
  1028. if (!(paramObject instanceof Integer))
  1029. {
  1030. popContext();
  1031. i = j;
  1032. }
  1033. }
  1034. }
  1035. localObject2 = localObject1;
  1036. if (paramMap.getClass() == JSONObject.class)
  1037. if (localObject1 != null)
  1038. break label1404;
  1039. label1404: for (localObject2 = "null"; ; localObject2 = localObject1.toString())
  1040. {
  1041. if (k != 34)
  1042. break label2008;
  1043. localJSONLexer.scanString();
  1044. String str = localJSONLexer.stringVal();
  1045. localObject1 = str;
  1046. localObject3 = localObject1;
  1047. if (localJSONLexer.isEnabled(Feature.AllowISO8601DateFormat))
  1048. {
  1049. localObject3 = new JSONScanner(str);
  1050. if (((JSONScanner)localObject3).scanISO8601DateIfMatch())
  1051. localObject1 = ((JSONScanner)localObject3).getCalendar().getTime();
  1052. ((JSONScanner)localObject3).close();
  1053. localObject3 = localObject1;
  1054. }
  1055. paramMap.put(localObject2, localObject3);
  1056. localJSONLexer.skipWhitespace();
  1057. j = localJSONLexer.getCurrent();
  1058. if (j != 44)
  1059. break label1867;
  1060. localJSONLexer.next();
  1061. j = i;
  1062. break;
  1063. }
  1064. }
  1065. label1414: label1956:
  1066. while (true)
  1067. {
  1068. localJSONLexer.scanNumber();
  1069. if (localJSONLexer.token() == 2);
  1070. for (localObject1 = localJSONLexer.integerValue(); ; localObject1 = localJSONLexer.numberValue())
  1071. {
  1072. paramMap.put(localObject2, localObject1);
  1073. break;
  1074. }
  1075. label1867: label1997: label2000: label2003: label2008:
  1076. do
  1077. {
  1078. if (k == 91)
  1079. {
  1080. localJSONLexer.nextToken();
  1081. localObject1 = new JSONArray();
  1082. parseArray((Collection)localObject1, localObject2);
  1083. paramMap.put(localObject2, localObject1);
  1084. if (localJSONLexer.token() == 13)
  1085. {
  1086. localJSONLexer.nextToken();
  1087. setContext(localParseContext);
  1088. return paramMap;
  1089. }
  1090. j = i;
  1091. if (localJSONLexer.token() == 16)
  1092. break;
  1093. throw new JSONException("syntax error");
  1094. }
  1095. if (k == 123)
  1096. {
  1097. localJSONLexer.nextToken();
  1098. localObject1 = parseObject(new JSONObject(), localObject2);
  1099. checkMapResolve(paramMap, localObject2.toString());
  1100. if (paramMap.getClass() == JSONObject.class)
  1101. paramMap.put(localObject2.toString(), localObject1);
  1102. while (true)
  1103. {
  1104. setContext(localParseContext, localObject1, localObject2);
  1105. if (localJSONLexer.token() != 13)
  1106. break;
  1107. localJSONLexer.nextToken();
  1108. setContext(localParseContext);
  1109. setContext(localParseContext);
  1110. return paramMap;
  1111. paramMap.put(localObject2, localObject1);
  1112. }
  1113. j = i;
  1114. if (localJSONLexer.token() == 16)
  1115. break;
  1116. throw new JSONException("syntax error, " + localJSONLexer.tokenName());
  1117. }
  1118. localJSONLexer.nextToken();
  1119. localObject3 = parse();
  1120. localObject1 = localObject2;
  1121. if (paramMap.getClass() == JSONObject.class)
  1122. localObject1 = localObject2.toString();
  1123. paramMap.put(localObject1, localObject3);
  1124. if (localJSONLexer.token() == 13)
  1125. {
  1126. localJSONLexer.nextToken();
  1127. setContext(localParseContext);
  1128. return paramMap;
  1129. }
  1130. j = i;
  1131. if (localJSONLexer.token() == 16)
  1132. break;
  1133. throw new JSONException("syntax error, position at " + localJSONLexer.pos() + ", name " + localObject1);
  1134. if (j == 125)
  1135. {
  1136. localJSONLexer.next();
  1137. localJSONLexer.resetStringPosition();
  1138. localJSONLexer.nextToken();
  1139. setContext(paramMap, paramObject);
  1140. setContext(localParseContext);
  1141. return paramMap;
  1142. }
  1143. throw new JSONException("syntax error, position at " + localJSONLexer.pos() + ", name " + localObject2);
  1144. if (((k >= 48) && (k <= 57)) || (k == 45))
  1145. break label412;
  1146. if (k == 123)
  1147. break label520;
  1148. if (k != 91)
  1149. break label622;
  1150. break label520;
  1151. break label978;
  1152. break label978;
  1153. paramMap = null;
  1154. break label978;
  1155. if ((k >= 48) && (k <= 57))
  1156. break label1414;
  1157. }
  1158. while (k != 45);
  1159. }
  1160. }
  1161. public void parseObject(Object paramObject)
  1162. {
  1163. Class localClass = paramObject.getClass();
  1164. Map localMap = this.config.getFieldDeserializers(localClass);
  1165. if ((this.lexer.token() != 12) && (this.lexer.token() != 16))
  1166. {
  1167. throw new JSONException("syntax error, expect {, actual " + this.lexer.tokenName());
  1168. if ((this.lexer.token() != 16) || (!isEnabled(Feature.AllowArbitraryCommas)))
  1169. break label147;
  1170. }
  1171. label147: FieldDeserializer localFieldDeserializer;
  1172. do
  1173. {
  1174. localObject1 = this.lexer.scanSymbol(this.symbolTable);
  1175. if (localObject1 == null)
  1176. {
  1177. if (this.lexer.token() != 13)
  1178. break;
  1179. this.lexer.nextToken(16);
  1180. return;
  1181. }
  1182. localFieldDeserializer = (FieldDeserializer)localMap.get(localObject1);
  1183. if (localFieldDeserializer != null)
  1184. break label254;
  1185. if (!isEnabled(Feature.IgnoreNotMatch))
  1186. throw new JSONException("setter not found, class " + localClass.getName() + ", property " + (String)localObject1);
  1187. this.lexer.nextTokenWithColon();
  1188. parse();
  1189. }
  1190. while (this.lexer.token() != 13);
  1191. this.lexer.nextToken();
  1192. return;
  1193. label254: Object localObject2 = localFieldDeserializer.getFieldClass();
  1194. Object localObject1 = localFieldDeserializer.getFieldType();
  1195. if (localObject2 == Integer.TYPE)
  1196. {
  1197. this.lexer.nextTokenWithColon(2);
  1198. localObject1 = IntegerDeserializer.instance.deserialze(this, (Type)localObject1, null);
  1199. }
  1200. while (true)
  1201. {
  1202. localFieldDeserializer.setValue(paramObject, localObject1);
  1203. if ((this.lexer.token() == 16) || (this.lexer.token() != 13))
  1204. break;
  1205. this.lexer.nextToken(16);
  1206. return;
  1207. if (localObject2 == String.class)
  1208. {
  1209. this.lexer.nextTokenWithColon(4);
  1210. localObject1 = StringDeserializer.deserialze(this);
  1211. }
  1212. else if (localObject2 == Long.TYPE)
  1213. {
  1214. this.lexer.nextTokenWithColon(2);
  1215. localObject1 = LongDeserializer.instance.deserialze(this, (Type)localObject1, null);
  1216. }
  1217. else
  1218. {
  1219. localObject2 = this.config.getDeserializer((Class)localObject2, (Type)localObject1);
  1220. this.lexer.nextTokenWithColon(((ObjectDeserializer)localObject2).getFastMatchToken());
  1221. localObject1 = ((ObjectDeserializer)localObject2).deserialze(this, (Type)localObject1, null);
  1222. }
  1223. }
  1224. }
  1225. public void popContext()
  1226. {
  1227. if (isEnabled(Feature.DisableCircularReferenceDetect))
  1228. return;
  1229. this.context = this.context.getParentContext();
  1230. this.contextArray[(this.contextArrayIndex - 1)] = null;
  1231. this.contextArrayIndex -= 1;
  1232. }
  1233. public void setConfig(ParserConfig paramParserConfig)
  1234. {
  1235. this.config = paramParserConfig;
  1236. }
  1237. public ParseContext setContext(ParseContext paramParseContext, Object paramObject1, Object paramObject2)
  1238. {
  1239. if (isEnabled(Feature.DisableCircularReferenceDetect))
  1240. return null;
  1241. this.context = new ParseContext(paramParseContext, paramObject1, paramObject2);
  1242. addContext(this.context);
  1243. return this.context;
  1244. }
  1245. public ParseContext setContext(Object paramObject1, Object paramObject2)
  1246. {
  1247. if (isEnabled(Feature.DisableCircularReferenceDetect))
  1248. return null;
  1249. return setContext(this.context, paramObject1, paramObject2);
  1250. }
  1251. public void setContext(ParseContext paramParseContext)
  1252. {
  1253. if (isEnabled(Feature.DisableCircularReferenceDetect))
  1254. return;
  1255. this.context = paramParseContext;
  1256. }
  1257. public void setDateFomrat(DateFormat paramDateFormat)
  1258. {
  1259. this.dateFormat = paramDateFormat;
  1260. }
  1261. public void setDateFormat(String paramString)
  1262. {
  1263. this.dateFormatPattern = paramString;
  1264. this.dateFormat = null;
  1265. }
  1266. public void setResolveStatus(int paramInt)
  1267. {
  1268. this.resolveStatus = paramInt;
  1269. }
  1270. public static class ResolveTask
  1271. {
  1272. private final ParseContext context;
  1273. private FieldDeserializer fieldDeserializer;
  1274. private ParseContext ownerContext;
  1275. private final String referenceValue;
  1276. public ResolveTask(ParseContext paramParseContext, String paramString)
  1277. {
  1278. this.context = paramParseContext;
  1279. this.referenceValue = paramString;
  1280. }
  1281. public ParseContext getContext()
  1282. {
  1283. return this.context;
  1284. }
  1285. public FieldDeserializer getFieldDeserializer()
  1286. {
  1287. return this.fieldDeserializer;
  1288. }
  1289. public ParseContext getOwnerContext()
  1290. {
  1291. return this.ownerContext;
  1292. }
  1293. public String getReferenceValue()
  1294. {
  1295. return this.referenceValue;
  1296. }
  1297. public void setFieldDeserializer(FieldDeserializer paramFieldDeserializer)
  1298. {
  1299. this.fieldDeserializer = paramFieldDeserializer;
  1300. }
  1301. public void setOwnerContext(ParseContext paramParseContext)
  1302. {
  1303. this.ownerContext = paramParseContext;
  1304. }
  1305. }
  1306. }
  1307. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  1308. * Qualified Name: com.alibaba.fastjson.parser.DefaultJSONParser
  1309. * JD-Core Version: 0.6.2
  1310. */