Parsing yaml file using snakeyaml with integer as key

可紊 提交于 2019-12-23 23:51:06

问题


I am trying to parse a yaml file that I did not create, and one that I cannot edit. The structure of the file is

681:
  activities:
    copying:
      time: 480
    manufacturing:
      materials:
      - quantity: 86
        typeID: 38
      products:
      - quantity: 1
        typeID: 165
      time: 600
    research_material:
      time: 210
    research_time:
      time: 210
  blueprintTypeID: 681
  maxProductionLimit: 300

The file is ~144,000 lines in length, each following the aforementioned structure. The problem I'm having is, because it's being parsed into POJOs using reflection, the very first key (in this case 681:) in the structure is an integer. Fields in Java cannot be named solely a numerical value, so when the parsing happens, I get the following error:

Exception in thread "main" Can't construct a java object for tag:yaml.org,2002:org.zephyrion.eve.assetmanager.Blueprint; exception=Cannot create property=682 for JavaBean=org.zephyrion.eve.assetmanager.Blueprint@2446bd09; No JavaBean properties found in org.zephyrion.eve.assetmanager.Blueprint
 in 'reader', line 1, column 1:
    681:
    ^

Is there a way to prevent the snakeyaml from parsing the value as an integer, and instead parse it as a string? I've tried using a custom resolver, and disabling resolving of integers all together, and that still did not work.

来源:https://stackoverflow.com/questions/26687844/parsing-yaml-file-using-snakeyaml-with-integer-as-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!