/QingTingFanBianYi/src/com/alibaba/fastjson/parser/deserializer/EnumDeserializer.java

https://gitlab.com/qt-prometheus/qt-prometheus · Java · 91 lines · 81 code · 6 blank · 4 comment · 11 complexity · 3caf9c4a61634bbf00a7d39c69154297 MD5 · raw file

  1. package com.alibaba.fastjson.parser.deserializer;
  2. import com.alibaba.fastjson.JSONException;
  3. import com.alibaba.fastjson.parser.DefaultJSONParser;
  4. import com.alibaba.fastjson.parser.JSONLexer;
  5. import java.lang.reflect.Method;
  6. import java.lang.reflect.Type;
  7. import java.util.HashMap;
  8. import java.util.Map;
  9. public class EnumDeserializer
  10. implements ObjectDeserializer
  11. {
  12. private final Class<?> enumClass;
  13. private final Map<String, Enum> nameMap = new HashMap();
  14. private final Map<Integer, Enum> ordinalMap = new HashMap();
  15. public EnumDeserializer(Class<?> paramClass)
  16. {
  17. this.enumClass = paramClass;
  18. try
  19. {
  20. Object[] arrayOfObject = (Object[])paramClass.getMethod("values", new Class[0]).invoke(null, new Object[0]);
  21. int j = arrayOfObject.length;
  22. int i = 0;
  23. while (i < j)
  24. {
  25. Enum localEnum = (Enum)arrayOfObject[i];
  26. this.ordinalMap.put(Integer.valueOf(localEnum.ordinal()), localEnum);
  27. this.nameMap.put(localEnum.name(), localEnum);
  28. i += 1;
  29. }
  30. }
  31. catch (Exception localException)
  32. {
  33. throw new JSONException("init enum values error, " + paramClass.getName());
  34. }
  35. }
  36. public <T> T deserialze(DefaultJSONParser paramDefaultJSONParser, Type paramType, Object paramObject)
  37. {
  38. try
  39. {
  40. paramType = paramDefaultJSONParser.getLexer();
  41. if (paramType.token() == 2)
  42. {
  43. paramDefaultJSONParser = Integer.valueOf(paramType.intValue());
  44. paramType.nextToken(16);
  45. paramType = this.ordinalMap.get(paramDefaultJSONParser);
  46. if (paramType != null)
  47. break label232;
  48. throw new JSONException("parse enum " + this.enumClass.getName() + " error, value : " + paramDefaultJSONParser);
  49. }
  50. }
  51. catch (JSONException paramDefaultJSONParser)
  52. {
  53. throw paramDefaultJSONParser;
  54. if (paramType.token() == 4)
  55. {
  56. paramDefaultJSONParser = paramType.stringVal();
  57. paramType.nextToken(16);
  58. if (paramDefaultJSONParser.length() == 0)
  59. return (Object)null;
  60. this.nameMap.get(paramDefaultJSONParser);
  61. return Enum.valueOf(this.enumClass, paramDefaultJSONParser);
  62. }
  63. if (paramType.token() == 8)
  64. {
  65. paramType.nextToken(16);
  66. return null;
  67. }
  68. }
  69. catch (Throwable paramDefaultJSONParser)
  70. {
  71. throw new JSONException(paramDefaultJSONParser.getMessage(), paramDefaultJSONParser);
  72. }
  73. paramDefaultJSONParser = paramDefaultJSONParser.parse();
  74. throw new JSONException("parse enum " + this.enumClass.getName() + " error, value : " + paramDefaultJSONParser);
  75. label232: return paramType;
  76. }
  77. public int getFastMatchToken()
  78. {
  79. return 2;
  80. }
  81. }
  82. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  83. * Qualified Name: com.alibaba.fastjson.parser.deserializer.EnumDeserializer
  84. * JD-Core Version: 0.6.2
  85. */