Parsing yaml file using snakeyaml with integer as

2019-07-31 16:23发布

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.

0条回答
登录 后发表回答