/src/test/java/data/media/MediaGenDecoder.java

https://github.com/alibaba/fastjson · Java · 316 lines · 273 code · 41 blank · 2 comment · 114 complexity · 4e612d4cbcd177dd8d4f1bedf63941e5 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 MediaGenDecoder 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 char[] duration_gen_prefix__ = "\"duration\":".toCharArray();
  17. private char[] bitrate_gen_prefix__ = "\"bitrate\":".toCharArray();
  18. private char[] persons_gen_prefix__ = "\"persons\":".toCharArray();
  19. private char[] player_gen_prefix__ = "\"player\":".toCharArray();
  20. private char[] copyright_gen_prefix__ = "\"copyright\":".toCharArray();
  21. private char[] format_gen_prefix__ = "\"format\":".toCharArray();
  22. private ObjectDeserializer uri_gen_deser__;
  23. private ObjectDeserializer title_gen_deser__;
  24. private ObjectDeserializer persons_gen_list_item_deser__;
  25. private Type persons_gen_list_item_type__ = java.lang.String.class;
  26. private ObjectDeserializer copyright_gen_deser__;
  27. private ObjectDeserializer format_gen_deser__;
  28. private ObjectDeserializer player_gen_deser__;
  29. public MediaGenDecoder (ParserConfig config, Class clazz) {
  30. super(config, clazz);
  31. // data.media.Media.Player
  32. player_gen_deser__ = config.getDeserializer(data.media.Media.Player.class);
  33. }
  34. public Object createInstance(DefaultJSONParser parser, Type type) {
  35. return new Media();
  36. }
  37. public Object deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
  38. JSONLexerBase lexer = (JSONLexerBase) parser.getLexer();
  39. if (!lexer.isEnabled(Feature.SortFeidFastMatch)) {
  40. return super.deserialze(parser, type, fieldName);
  41. }
  42. if (lexer.isEnabled(Feature.SupportArrayToBean)) {
  43. // deserialzeArrayMapping
  44. }
  45. if (lexer.scanType("Department") == JSONLexerBase.NOT_MATCH) {
  46. return super.deserialze(parser, type, fieldName);
  47. }
  48. ParseContext mark_context = parser.getContext();
  49. int matchedCount = 0;
  50. Media instance = new Media();
  51. ParseContext context = parser.getContext();
  52. ParseContext childContext = parser.setContext(context, instance, fieldName);
  53. if (lexer.matchStat == JSONLexerBase.END) {
  54. return instance;
  55. }
  56. int matchStat = 0;
  57. int _asm_flag_0 = 0;
  58. int bitrate_gen = 0;
  59. String copyright_gen;
  60. if (lexer.isEnabled(Feature.InitStringFieldAsEmpty)) {
  61. copyright_gen = lexer.stringDefaultValue();
  62. _asm_flag_0 |= 2;
  63. } else {
  64. copyright_gen = null;
  65. }
  66. long duration_gen = 0;
  67. String format_gen;
  68. if (lexer.isEnabled(Feature.InitStringFieldAsEmpty)) {
  69. format_gen = lexer.stringDefaultValue();
  70. _asm_flag_0 |= 8;
  71. } else {
  72. format_gen = null;
  73. }
  74. int height_gen = 0;
  75. java.util.List persons_gen = null;
  76. data.media.Media.Player player_gen = null;
  77. long size_gen = 0;
  78. String title_gen;
  79. if (lexer.isEnabled(Feature.InitStringFieldAsEmpty)) {
  80. title_gen = lexer.stringDefaultValue();
  81. _asm_flag_0 |= 256;
  82. } else {
  83. title_gen = null;
  84. }
  85. String uri_gen;
  86. if (lexer.isEnabled(Feature.InitStringFieldAsEmpty)) {
  87. uri_gen = lexer.stringDefaultValue();
  88. _asm_flag_0 |= 512;
  89. } else {
  90. uri_gen = null;
  91. }
  92. int width_gen = 0;
  93. boolean endFlag = false, restFlag = false;
  94. if ((!endFlag) && (!restFlag)) {
  95. bitrate_gen = lexer.scanFieldInt(bitrate_gen_prefix__);
  96. if(lexer.matchStat > 0) {
  97. _asm_flag_0 |= 1;
  98. matchedCount++;
  99. }
  100. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  101. restFlag = true;
  102. }
  103. if(lexer.matchStat == JSONLexerBase.END) {
  104. endFlag = true;
  105. }
  106. }
  107. if ((!endFlag) && (!restFlag)) {
  108. copyright_gen = lexer.scanFieldString(copyright_gen_prefix__);
  109. if(lexer.matchStat > 0) {
  110. _asm_flag_0 |= 2;
  111. matchedCount++;
  112. }
  113. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  114. restFlag = true;
  115. }
  116. if(lexer.matchStat == JSONLexerBase.END) {
  117. endFlag = true;
  118. }
  119. }
  120. if ((!endFlag) && (!restFlag)) {
  121. duration_gen = lexer.scanFieldLong(duration_gen_prefix__);
  122. if(lexer.matchStat > 0) {
  123. _asm_flag_0 |= 4;
  124. matchedCount++;
  125. }
  126. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  127. restFlag = true;
  128. }
  129. if(lexer.matchStat == JSONLexerBase.END) {
  130. endFlag = true;
  131. }
  132. }
  133. if ((!endFlag) && (!restFlag)) {
  134. format_gen = lexer.scanFieldString(format_gen_prefix__);
  135. if(lexer.matchStat > 0) {
  136. _asm_flag_0 |= 8;
  137. matchedCount++;
  138. }
  139. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  140. restFlag = true;
  141. }
  142. if(lexer.matchStat == JSONLexerBase.END) {
  143. endFlag = true;
  144. }
  145. }
  146. if ((!endFlag) && (!restFlag)) {
  147. height_gen = lexer.scanFieldInt(height_gen_prefix__);
  148. if(lexer.matchStat > 0) {
  149. _asm_flag_0 |= 16;
  150. matchedCount++;
  151. }
  152. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  153. restFlag = true;
  154. }
  155. if(lexer.matchStat == JSONLexerBase.END) {
  156. endFlag = true;
  157. }
  158. }
  159. if ((!endFlag) && (!restFlag)) {
  160. persons_gen = (java.util.List) lexer.scanFieldStringArray(persons_gen_prefix__, java.util.List.class);
  161. if(lexer.matchStat > 0) {
  162. _asm_flag_0 |= 32;
  163. matchedCount++;
  164. }
  165. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  166. restFlag = true;
  167. }
  168. if(lexer.matchStat == JSONLexerBase.END) {
  169. endFlag = true;
  170. }
  171. }
  172. if ((!endFlag) && (!restFlag)) {
  173. player_gen = (data.media.Media.Player) this.scanEnum(lexer, player_gen_prefix__, player_gen_deser__);
  174. if(lexer.matchStat > 0) {
  175. _asm_flag_0 |= 64;
  176. matchedCount++;
  177. }
  178. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  179. restFlag = true;
  180. }
  181. if(lexer.matchStat == JSONLexerBase.END) {
  182. endFlag = true;
  183. }
  184. }
  185. if ((!endFlag) && (!restFlag)) {
  186. size_gen = lexer.scanFieldLong(size_gen_prefix__);
  187. if(lexer.matchStat > 0) {
  188. _asm_flag_0 |= 128;
  189. matchedCount++;
  190. }
  191. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  192. restFlag = true;
  193. }
  194. if(lexer.matchStat == JSONLexerBase.END) {
  195. endFlag = true;
  196. }
  197. }
  198. if ((!endFlag) && (!restFlag)) {
  199. title_gen = lexer.scanFieldString(title_gen_prefix__);
  200. if(lexer.matchStat > 0) {
  201. _asm_flag_0 |= 256;
  202. matchedCount++;
  203. }
  204. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  205. restFlag = true;
  206. }
  207. if(lexer.matchStat == JSONLexerBase.END) {
  208. endFlag = true;
  209. }
  210. }
  211. if ((!endFlag) && (!restFlag)) {
  212. uri_gen = lexer.scanFieldString(uri_gen_prefix__);
  213. if(lexer.matchStat > 0) {
  214. _asm_flag_0 |= 512;
  215. matchedCount++;
  216. }
  217. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  218. restFlag = true;
  219. }
  220. if(lexer.matchStat == JSONLexerBase.END) {
  221. endFlag = true;
  222. }
  223. }
  224. if ((!endFlag) && (!restFlag)) {
  225. width_gen = lexer.scanFieldInt(width_gen_prefix__);
  226. if(lexer.matchStat > 0) {
  227. _asm_flag_0 |= 1024;
  228. matchedCount++;
  229. }
  230. if(lexer.matchStat == JSONLexerBase.NOT_MATCH) {
  231. restFlag = true;
  232. }
  233. if(lexer.matchStat != JSONLexerBase.END) {
  234. restFlag = true;
  235. }
  236. }
  237. if ((_asm_flag_0 & 1) != 0) {
  238. instance.setBitrate(bitrate_gen);
  239. }
  240. if ((_asm_flag_0 & 2) != 0) {
  241. instance.setCopyright(copyright_gen);
  242. }
  243. if ((_asm_flag_0 & 4) != 0) {
  244. instance.setDuration(duration_gen);
  245. }
  246. if ((_asm_flag_0 & 8) != 0) {
  247. instance.setFormat(format_gen);
  248. }
  249. if ((_asm_flag_0 & 16) != 0) {
  250. instance.setHeight(height_gen);
  251. }
  252. if ((_asm_flag_0 & 32) != 0) {
  253. instance.setPersons(persons_gen);
  254. }
  255. if ((_asm_flag_0 & 64) != 0) {
  256. instance.setPlayer(player_gen);
  257. }
  258. if ((_asm_flag_0 & 128) != 0) {
  259. instance.setSize(size_gen);
  260. }
  261. if ((_asm_flag_0 & 256) != 0) {
  262. instance.setTitle(title_gen);
  263. }
  264. if ((_asm_flag_0 & 512) != 0) {
  265. instance.setUri(uri_gen);
  266. }
  267. if ((_asm_flag_0 & 1024) != 0) {
  268. instance.setWidth(width_gen);
  269. }
  270. if (restFlag) {
  271. return super.parseRest(parser, type, fieldName, instance, 0, new int[0]);
  272. }
  273. return instance;
  274. }
  275. }