Nested list in YAML file - having trouble with class creation in VB.net (eve online SDE)

455 Views Asked by At

I pretty new to the YAML format and VB.net in general (worked with VB6 for ~5 years at work and migrating over, this project is a bit of a learning exercise). I am also using the yamldotnet package.

At the moment I am modifying some code that was posted to parse a .yaml file from the Eve Online SDE since since the SDE has added new fields to the yaml file. Ideally I would like to use this file over making calls to the API to get static information from the SDE files.

I am getting stuck adding properties to the 'temporary' class for the 'masteries' field. I have redacted the en/de/fr/etc. descriptions to ease reading.

582:
capacity: 270.0
description:
    de: info
    en: info
    fr: info
    ja: info
    ru: info
    zh: info
factionID: 500001
graphicID: 38
groupID: 25
marketGroupID: 61
mass: 1480000.0
masteries:
    0:
    - 96
    - 139
    - 85
    - 87
    - 94
    1:
    - 96
    - 139
    - 85
    - 87
    - 94
    2:
    - 96
    - 139
    - 85
    - 87
    - 94
    3:
    - 96
    - 139
    - 85
    - 87
    - 94
    4:
    - 96
    - 139
    - 85
    - 118
    - 87
    - 94
name:
    de: Bantam
    en: Bantam
    fr: Bantam
    ja: バンタム
    ru: Bantam
    zh: 矮脚鸡级
portionSize: 1
published: true
raceID: 1
radius: 27.0
sofFactionName: caldaribase
soundID: 20070
traits:
    roleBonuses:
    -   bonus: 300
        bonusText:
            de: info
            en: info
            fr: info
            ja: info
            ru: info
            zh: info
        importance: 1
        unitID: 105
    types:
        3330:
        -   bonus: 10
            bonusText:
                de: info
                en: info
                fr: info
                ja: info
                ru: info
                zh: info
            importance: 1
            unitID: 105
        -   bonus: 10
            bonusText:
                de: info
                en: info
                fr: info
                ja: info
                ru: info
                zh: info
            importance: 2
            unitID: 105
volume: 20000.0

And the class I have, so far as I have been adding properties as

Class YAMLtempItem
    Public Property basePrice As Decimal?
    Public Property description As Dictionary(Of String, String)
    Public Property groupID As Integer
    Public Property iconID As Integer?
    Public Property marketGroupID As Integer?
    Public Property mass As String
    Public Property name As Dictionary(Of String, String)
    Public Property portionSize As Integer
    Public Property published As Boolean
    Public Property volume As Decimal?
    Public Property radius As Double?
    Public Property graphicID As Integer?
    Public Property soundID As Integer?
    Public Property raceID As Integer?
    Public Property sofFactionName As String
    Public Property capacity As String
    Public Property factionID As Integer?
    Public Property masteries As Dictionary(Of List(Of Integer), Integer)
End Class

and the code calling the parsing is as follows. At the moment it is just clicking a button to fire off the parsing process as this will end up being a module to add to a larger application.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    'Dim input = New StringReader("C:\....\typeIDs.yaml")
    Dim input = System.IO.File.ReadAllText("C:\Users\ahooks\Dropbox\Eve VB.net Projects\EVE Resources\Static Data YAML\typeIDs.yaml")
    TextBox3.Text = ""

    Dim deserializer = New Deserializer()
    Dim strtemp = New StringReader(input)
    Dim itemTypes = deserializer.Deserialize(Of Dictionary(Of Integer, YAMLtempItem))(strtemp)
End Sub

I have tried different combinations for the 'masteries' property but to no avail. I have also tried finding something similar to JSONUtils that will generate a class from some data but that came up short too. Anyone able to point me in the right direction for getting this nested list?

1

There are 1 best solutions below

0
On

It seems that the masteries property declaration is erroneous. You are declaring the keys to be lists of integers and the values to be integers, while the document has integers as keys and lists as values. So instead of

Public Property masteries As Dictionary(Of List(Of Integer), Integer)

you probably want

Public Property masteries As Dictionary(Integer, Of List(Of Integer))

Also, YamlDotNet assumes that your code follows the standard .NET naming conventions, and by default assumes camelCase in the YAML document. This means that your property names should be capitalized:

Class YAMLtempItem
    Public Property BasePrice As Decimal?
    Public Property Description As Dictionary(Of String, String)
    Public Property GroupID As Integer
    Public Property IconID As Integer?
    Public Property MarketGroupID As Integer?
    Public Property Mass As String
    Public Property Name As Dictionary(Of String, String)
    Public Property PortionSize As Integer
    Public Property Published As Boolean
    Public Property Volume As Decimal?
    Public Property Radius As Double?
    Public Property GraphicID As Integer?
    Public Property SoundID As Integer?
    Public Property RaceID As Integer?
    Public Property SofFactionName As String
    Public Property Capacity As String
    Public Property FactionID As Integer?
    Public Property Masteries As Dictionary(Of List(Of Integer), Integer)
End Class