/src/test/java/data/media/ImageGenDecoder.java

https://github.com/alibaba/fastjson · Java · 179 lines · 149 code · 29 blank · 1 comment · 56 complexity · 5579561861fd286b23912de173abd52f MD5 · raw file

  1. package data.media;
  2. import java.lang.reflect.Type;
  3. import com.alibaba.fastjson.parser.DefaultJSONParser;
  4. import com.alibaba.fastjson.parser.Feature;
  5. import com.alibaba.fastjson.parser.JSONLexerBase;
  6. import com.alibaba.fastjson.parser.ParseContext;
  7. import com.alibaba.fastjson.parser.ParserConfig;
  8. import com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer;
  9. import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
  10. public class ImageGenDecoder extends JavaBeanDeserializer implements ObjectDeserializer {
  11. private char[] size_gen_prefix__ = "\"size\":".toCharArray();
  12. private char[] uri_gen_prefix__ = "\"uri\":".toCharArray();
  13. private char[] title_gen_prefix__ = "\"title\":".toCharArray();
  14. private char[] width_gen_prefix__ = "\"width\":".toCharArray();
  15. private char[] height_gen_prefix__ = "\"height\":".toCharArray();
  16. private ObjectDeserializer uri_gen_deser__;
  17. private ObjectDeserializer title_gen_deser__;
  18. private ObjectDeserializer size_gen_deser__;
  19. public ImageGenDecoder (ParserConfig config, Class clazz) {
  20. super(config, clazz);
  21. size_gen_deser__ = config.getDeserializer(data.media.Image.Size.class);
  22. }
  23. public Object createInstance(DefaultJSONParser parser, Type type) {
  24. return new Image();
  25. }
  26. public Object deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
  27. JSONLexerBase lexer = (JSONLexerBase) parser.getLexer();
  28. if (!lexer.isEnabled(Feature.SortFeidFastMatch)) {
  29. return super.deserialze(parser, type, fieldName);
  30. }
  31. if (lexer.isEnabled(Feature.SupportArrayToBean)) {
  32. // deserialzeArrayMapping
  33. }
  34. if (lexer.scanType("Department") == JSONLexerBase.NOT_MATCH) {
  35. return super.deserialze(parser, type, fieldName);
  36. }
  37. ParseContext mark_context = parser.getContext();
  38. int matchedCount = 0;
  39. Image instance = new Image();
  40. ParseContext context = parser.getContext();
  41. ParseContext childContext = parser.setContext(context, instance, fieldName);
  42. if (lexer.matchStat == JSONLexerBase.END) {
  43. return instance;
  44. }
  45. int matchStat = 0;
  46. int _asm_flag_0 = 0;
  47. int height_gen = 0;
  48. data.media.Image.Size size_gen = null;
  49. String title_gen;
  50. if (lexer.isEnabled(Feature.InitStringFieldAsEmpty)) {
  51. title_gen = lexer.stringDefaultValue();
  52. _asm_flag_0 |= 4;
  53. } else {
  54. title_gen = null;
  55. }
  56. String uri_gen;
  57. if (lexer.isEnabled(Feature.InitStringFieldAsEmpty)) {
  58. uri_gen = lexer.stringDefaultValue();
  59. _asm_flag_0 |= 8;
  60. } else {
  61. uri_gen = null;
  62. }
  63. int width_gen = 0;
  64. boolean endFlag = false, restFlag = false;
  65. if ((!endFlag) && (!restFlag)) {
  66. height_gen = lexer.scanFieldInt(height_gen_prefix__);
  67. if(lexer.matchStat > 0) {
  68. _asm_flag_0 |= 1;
  69. matchedCount++;
  70. }
  71. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  72. restFlag = true;
  73. }
  74. if(lexer.matchStat == JSONLexerBase.END) {
  75. endFlag = true;
  76. }
  77. }
  78. if ((!endFlag) && (!restFlag)) {
  79. size_gen = (data.media.Image.Size) this.scanEnum(lexer, size_gen_prefix__, size_gen_deser__);
  80. if(lexer.matchStat > 0) {
  81. _asm_flag_0 |= 2;
  82. matchedCount++;
  83. }
  84. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  85. restFlag = true;
  86. }
  87. if(lexer.matchStat == JSONLexerBase.END) {
  88. endFlag = true;
  89. }
  90. }
  91. if ((!endFlag) && (!restFlag)) {
  92. title_gen = lexer.scanFieldString(title_gen_prefix__);
  93. if(lexer.matchStat > 0) {
  94. _asm_flag_0 |= 4;
  95. matchedCount++;
  96. }
  97. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  98. restFlag = true;
  99. }
  100. if(lexer.matchStat == JSONLexerBase.END) {
  101. endFlag = true;
  102. }
  103. }
  104. if ((!endFlag) && (!restFlag)) {
  105. uri_gen = lexer.scanFieldString(uri_gen_prefix__);
  106. if(lexer.matchStat > 0) {
  107. _asm_flag_0 |= 8;
  108. matchedCount++;
  109. }
  110. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  111. restFlag = true;
  112. }
  113. if(lexer.matchStat == JSONLexerBase.END) {
  114. endFlag = true;
  115. }
  116. }
  117. if ((!endFlag) && (!restFlag)) {
  118. width_gen = lexer.scanFieldInt(width_gen_prefix__);
  119. if(lexer.matchStat > 0) {
  120. _asm_flag_0 |= 16;
  121. matchedCount++;
  122. }
  123. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  124. restFlag = true;
  125. }
  126. if(lexer.matchStat != JSONLexerBase.END) {
  127. restFlag = true;
  128. }
  129. }
  130. if ((_asm_flag_0 & 1) != 0) {
  131. instance.setHeight(height_gen);
  132. }
  133. if ((_asm_flag_0 & 2) != 0) {
  134. instance.setSize(size_gen);
  135. }
  136. if ((_asm_flag_0 & 4) != 0) {
  137. instance.setTitle(title_gen);
  138. }
  139. if ((_asm_flag_0 & 8) != 0) {
  140. instance.setUri(uri_gen);
  141. }
  142. if ((_asm_flag_0 & 16) != 0) {
  143. instance.setWidth(width_gen);
  144. }
  145. if (restFlag) {
  146. return super.parseRest(parser, type, fieldName, instance, 0, new int[0]);
  147. }
  148. return instance;
  149. }
  150. }