Imports System.Collections
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Reflection
Imports Newtonsoft.Json.Linq
Imports Newtonsoft.Json.Converters
Imports Newtonsoft.Json.Serialization
<JsonProperty("e")> Public MessageType As String
<JsonProperty("data")> Public MessageData As Object
<JsonProperty("ok")> Public MessageOk As String
Public Sub New(message As String)
JsonConvert.PopulateObject(message, Me)
Dim message1 as new XMessage() With { _
.MessageType = "My Message Type", _
.MessageData = "message data", _
.MessageOk = "Yes I am OK" _
Dim json1 = JsonConvert.SerializeObject(message1, Newtonsoft.Json.Formatting.Indented)
Console.WriteLine("Initial JSON: ")
Dim message2 = new XMessage(json1)
Dim json2 = JsonConvert.SerializeObject(message2, Newtonsoft.Json.Formatting.Indented)
Console.WriteLine(Environment.NewLine & "{0} constructed from that JSON and reserialized: ", message2)
Assert.IsTrue(json1 IS json2)
Console.WriteLine("Environment version: " & Environment.Version.ToString())
Console.WriteLine("Json.NET version: " & GetType(JsonSerializer).Assembly.FullName)
Console.WriteLine("Unhandled exception: ")
Public Class AssertionFailedException
Public Sub New(message As String)
Public Sub New(message As String, inner As Exception)
MyBase.New(message, inner)
Public Sub IsTrue(value as Boolean, Optional message as String = "failed")
Throw New AssertionFailedException(message)