Skip to content

Instantly share code, notes, and snippets.

@martea
Created February 4, 2021 07:47
Show Gist options
  • Save martea/f7531cf495c9c6e4235efe359246d8ce to your computer and use it in GitHub Desktop.
Save martea/f7531cf495c9c6e4235efe359246d8ce to your computer and use it in GitHub Desktop.
JsonElementConverter for newtonsoft
public class JsonElementConverter : Newtonsoft.Json.JsonConverter<System.Text.Json.JsonElement>
{
public JsonElementConverter()
{
}
public override System.Text.Json.JsonElement ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, [System.Diagnostics.CodeAnalysis.AllowNull] System.Text.Json.JsonElement existingValue, bool hasExistingValue, Newtonsoft.Json.JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, [System.Diagnostics.CodeAnalysis.AllowNull] System.Text.Json.JsonElement value, Newtonsoft.Json.JsonSerializer serializer)
{
//porting value conversion with json serializer and write it to the newtonsoft json writer.
writer.WriteRawValue(System.Text.Json.JsonSerializer.Serialize(value));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment