I want to deserialize a few VB.Net objects. Two classes of AllgTyp inherit here and are packed in a list.
If it were not a list, but non-nested objects, a simple JSON converter (how to deserialize JSON into IEnumerable<BaseType> with Newtonsoft JSON.NET) would be a solution. But how do I resolve the whole thing so that the nesting is deserialized?
Imports Newtonsoft.Json
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Install Newtonsoft over "View" > "Other Windows" > "Package Manager Console" -> type in:
'Install-Package Newtonsoft.Json
Dim output As String = JsonConvert.SerializeObject(testemal(), Formatting.Indented)
Dim deserializedProduct As List(Of AllgTyp) = JsonConvert.DeserializeObject(Of List(Of AllgTyp))(output)
End Sub
Private Function testemal() As List(Of AllgTyp)
Dim lstMarken As New List(Of AllgTyp)
Dim textmarken1 As New Verschachtelung("vorbriefanrede", "C:\tmp2\anrede.docx", "sdfs")
lstMarken.Add(textmarken1)
Dim textmarken2 As New Verschachtelung("inhalt", "C:\tmp2\DatMeinInhalt.docx", "sdfsdfinInhalt")
lstMarken.Add(textmarken2)
Dim aa As New Textmarke("datum", "24.02.2020")
textmarken2.Verschachtelung.Add(aa)
Dim ab As New Textmarke("Empfaenger", "isjdfosdfjosdjf")
textmarken2.Verschachtelung.Add(ab)
Dim c2 As New Verschachtelung("mbnmbnmbnm", "C:\tmp2\DatMeinInhalt.docx", "sfssfachinsdfsdfhalt1")
textmarken2.Verschachtelung.Add(c2)
Dim c3 As New Verschachtelung("sdfsfsfsss", "fsdf")
c2.Verschachtelung.Add(c3)
Dim c4 As New Verschachtelung("sdfsdf", "vo_fachinhalt3")
c3.Verschachtelung.Add(c4)
Dim c5 As New Verschachtelung("cbvcbcbcv", "vo_fachinhalt4")
c4.Verschachtelung.Add(c5)
Dim c6 As New Verschachtelung("vcbcvbcbcbc", "vo_fachinhalt5")
c4.Verschachtelung.Add(c6)
Return lstMarken
End Function
End Class
Public Class AllgTyp
Sub New()
End Sub
End Class
Public Class Textmarke
Inherits AllgTyp
Public textmarkenname As String
Public wert As String
Sub New()
End Sub
Sub New(textmarkenname As String, wert As String)
Me.textmarkenname = textmarkenname
Me.wert = wert
End Sub
End Class
Public Class Verschachtelung
Inherits AllgTyp
Public quellDatei As String
Public quelleBereich As String
Public zielBereich As String
Public Verschachtelung As New List(Of AllgTyp)
Sub New()
End Sub
Sub New(zielBereich As String, quelleBereich As String)
Me.New(zielBereich, Nothing, quelleBereich)
End Sub
Sub New(zielBereich As String, quellDatei As String, quelleBereich As String)
Me.zielBereich = zielBereich
Me.quellDatei = quellDatei
Me.quelleBereich = quelleBereich
End Sub
End Class