diff --git a/Directory.Packages.props b/Directory.Packages.props
index 0c02da37d..ead377ede 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -15,7 +15,6 @@
-
diff --git a/gen/DocumentFormat.OpenXml.Generator.Models/Converters/QualifiedNameConverter.cs b/gen/DocumentFormat.OpenXml.Generator.Models/Converters/QualifiedNameConverter.cs
index 16a5febd1..144055fd3 100644
--- a/gen/DocumentFormat.OpenXml.Generator.Models/Converters/QualifiedNameConverter.cs
+++ b/gen/DocumentFormat.OpenXml.Generator.Models/Converters/QualifiedNameConverter.cs
@@ -2,25 +2,26 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using DocumentFormat.OpenXml.Generator.Models;
-using Newtonsoft.Json;
+using System;
+using System.Text.Json;
+using System.Text.Json.Serialization;
namespace DocumentFormat.OpenXml.Generator.Converters;
internal class QualifiedNameConverter : JsonConverter
{
- public override QName? ReadJson(JsonReader reader, Type objectType, QName? existingValue, bool hasExistingValue, JsonSerializer serializer)
+ public override QName? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
- if (reader.TokenType != JsonToken.String)
+ if (reader.TokenType != JsonTokenType.String)
{
throw new InvalidOperationException("QName must be encoded as a string");
}
- var str = serializer.Deserialize(reader) ?? string.Empty;
-
+ var str = reader.GetString() ?? string.Empty;
return QName.Parse(str);
}
- public override void WriteJson(JsonWriter writer, QName? value, JsonSerializer serializer)
+ public override void Write(Utf8JsonWriter writer, QName value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
diff --git a/gen/DocumentFormat.OpenXml.Generator.Models/Converters/TypedQNameConverter.cs b/gen/DocumentFormat.OpenXml.Generator.Models/Converters/TypedQNameConverter.cs
index acecdcdbc..70456f10b 100644
--- a/gen/DocumentFormat.OpenXml.Generator.Models/Converters/TypedQNameConverter.cs
+++ b/gen/DocumentFormat.OpenXml.Generator.Models/Converters/TypedQNameConverter.cs
@@ -2,20 +2,22 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using DocumentFormat.OpenXml.Generator.Models;
-using Newtonsoft.Json;
+using System;
+using System.Text.Json;
+using System.Text.Json.Serialization;
namespace DocumentFormat.OpenXml.Generator.Converters;
internal class TypedQNameConverter : JsonConverter
{
- public override TypedQName? ReadJson(JsonReader reader, Type objectType, TypedQName? existingValue, bool hasExistingValue, JsonSerializer serializer)
+ public override TypedQName? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
- if (reader.TokenType != JsonToken.String)
+ if (reader.TokenType != JsonTokenType.String)
{
throw new InvalidOperationException("TypedQName must be encoded as a string");
}
- var str = serializer.Deserialize(reader) ?? string.Empty;
+ var str = reader.GetString() ?? string.Empty;
var split = str.Split('/');
if (split.Length != 2)
@@ -26,7 +28,7 @@ internal class TypedQNameConverter : JsonConverter
return new TypedQName(QName.Parse(split[0]), QName.Parse(split[1]));
}
- public override void WriteJson(JsonWriter writer, TypedQName? value, JsonSerializer serializer)
+ public override void Write(Utf8JsonWriter writer, TypedQName value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
diff --git a/gen/DocumentFormat.OpenXml.Generator.Models/DocumentFormat.OpenXml.Generator.Models.csproj b/gen/DocumentFormat.OpenXml.Generator.Models/DocumentFormat.OpenXml.Generator.Models.csproj
index d5ebe540a..6a11c3d57 100644
--- a/gen/DocumentFormat.OpenXml.Generator.Models/DocumentFormat.OpenXml.Generator.Models.csproj
+++ b/gen/DocumentFormat.OpenXml.Generator.Models/DocumentFormat.OpenXml.Generator.Models.csproj
@@ -9,7 +9,7 @@
DocumentFormat.OpenXml.Generator
-
+
diff --git a/gen/DocumentFormat.OpenXml.Generator.Models/OpenXmlGeneratorDataSource.cs b/gen/DocumentFormat.OpenXml.Generator.Models/OpenXmlGeneratorDataSource.cs
index 9ff0ef930..869fa3849 100644
--- a/gen/DocumentFormat.OpenXml.Generator.Models/OpenXmlGeneratorDataSource.cs
+++ b/gen/DocumentFormat.OpenXml.Generator.Models/OpenXmlGeneratorDataSource.cs
@@ -4,25 +4,25 @@
using DocumentFormat.OpenXml.Generator.Converters;
using DocumentFormat.OpenXml.Generator.Models;
using DocumentFormat.OpenXml.Generator.Schematron;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Converters;
using System.Collections.Immutable;
+using System.Text.Json;
+using System.Text.Json.Serialization;
namespace DocumentFormat.OpenXml.Generator;
public record OpenXmlGeneratorDataSource
{
- private static readonly JsonSerializerSettings _settings = new()
+ private static readonly JsonSerializerOptions _options = new()
{
Converters =
{
- new StringEnumConverter(),
+ new JsonStringEnumConverter(),
new QualifiedNameConverter(),
new TypedQNameConverter(),
},
};
- public static T? Deserialize(string? content) => content is null ? default : JsonConvert.DeserializeObject(content, _settings);
+ public static T? Deserialize(string? content) => content is null ? default : JsonSerializer.Deserialize(content, _options);
public ImmutableArray KnownNamespaces { get; init; } = ImmutableArray.Create();
diff --git a/gen/DocumentFormat.OpenXml.Generator/SourceGenerator.targets b/gen/DocumentFormat.OpenXml.Generator/SourceGenerator.targets
index 048cd0fe8..6bc09548c 100644
--- a/gen/DocumentFormat.OpenXml.Generator/SourceGenerator.targets
+++ b/gen/DocumentFormat.OpenXml.Generator/SourceGenerator.targets
@@ -7,10 +7,7 @@
-
-
-
-
+
diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets
index f77cf4244..84f6c225c 100644
--- a/test/Directory.Build.targets
+++ b/test/Directory.Build.targets
@@ -18,7 +18,6 @@
-
diff --git a/test/DocumentFormat.OpenXml.Framework.Tests/TestUtility.cs b/test/DocumentFormat.OpenXml.Framework.Tests/TestUtility.cs
index 49c147202..c968a1834 100644
--- a/test/DocumentFormat.OpenXml.Framework.Tests/TestUtility.cs
+++ b/test/DocumentFormat.OpenXml.Framework.Tests/TestUtility.cs
@@ -4,8 +4,10 @@
using System;
using System.IO;
using System.Reflection;
+using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
+using Xunit;
namespace DocumentFormat.OpenXml.Framework.Tests
{
@@ -13,6 +15,7 @@ internal static class TestUtility
{
private static readonly JsonSerializerOptions _options = new()
{
+ Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
Converters =
{
new OpenXmlNamespaceConverter(),
@@ -22,6 +25,17 @@ internal static class TestUtility
WriteIndented = true,
};
+ public static void ValidateJsonFileContentsAreEqual(Stream stream1, Stream stream2)
+ {
+ using var reader1 = new StreamReader(stream1);
+ using var reader2 = new StreamReader(stream2);
+
+ var expected = reader1.ReadToEnd().Replace("\r\n", "\n");
+ var actual = reader2.ReadToEnd().Replace("\r\n", "\n");
+
+ Assert.Equal(expected, actual);
+ }
+
#nullable enable
public static T? Deserialize(string name)
diff --git a/test/DocumentFormat.OpenXml.Packaging.Tests/ITestOutputHelperExtenstions.cs b/test/DocumentFormat.OpenXml.Packaging.Tests/ITestOutputHelperExtenstions.cs
index 920e5df48..1a3c8c77b 100644
--- a/test/DocumentFormat.OpenXml.Packaging.Tests/ITestOutputHelperExtenstions.cs
+++ b/test/DocumentFormat.OpenXml.Packaging.Tests/ITestOutputHelperExtenstions.cs
@@ -1,9 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-using DocumentFormat.OpenXml.Framework;
using DocumentFormat.OpenXml.Framework.Tests;
-using System;
using System.IO;
using Xunit;
@@ -11,13 +9,15 @@ namespace DocumentFormat.OpenXml.Tests
{
internal static class ITestOutputHelperExtenstions
{
- public static void WriteObjectToTempFile(this ITestOutputHelper output, string name, T obj)
+ public static string WriteObjectToTempFile(this ITestOutputHelper output, string name, T obj)
{
var tmp = Path.GetTempFileName();
output.WriteLine($"Wrote {name} to temp path {tmp}");
File.WriteAllText(tmp, TestUtility.Serialize(obj));
+
+ return tmp;
}
}
}
diff --git a/test/DocumentFormat.OpenXml.Packaging.Tests/PartConstraintRuleTests.cs b/test/DocumentFormat.OpenXml.Packaging.Tests/PartConstraintRuleTests.cs
index b69c4359b..0e6532c08 100644
--- a/test/DocumentFormat.OpenXml.Packaging.Tests/PartConstraintRuleTests.cs
+++ b/test/DocumentFormat.OpenXml.Packaging.Tests/PartConstraintRuleTests.cs
@@ -3,15 +3,17 @@
using DocumentFormat.OpenXml.Features;
using DocumentFormat.OpenXml.Framework;
+using DocumentFormat.OpenXml.Framework.Tests;
using DocumentFormat.OpenXml.Packaging;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Converters;
+using DocumentFormat.OpenXml.Packaging.Tests;
using NSubstitute;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
+using System.Text.Json;
+using System.Text.Json.Serialization;
using Xunit;
namespace DocumentFormat.OpenXml.Tests
@@ -86,10 +88,9 @@ public void ValidatePart(Type partType)
}
Assert.NotNull(expectedConstraints.Parts);
-#if DEBUG
+
_output.WriteObjectToTempFile("expected constraints", expectedConstraints.Parts.OrderBy(p => p.RelationshipType));
_output.WriteObjectToTempFile("actual constraints", constraints.Rules.OrderBy(p => p.RelationshipType).Select(p => new PartConstraintRule2(p)));
-#endif
Assert.Equal(
expectedConstraints.Parts.OrderBy(p => p.RelationshipType),
@@ -119,7 +120,13 @@ public void ExportData()
})
.OrderBy(d => d.Name, StringComparer.Ordinal);
- _output.WriteObjectToTempFile("typed parts", result);
+ var output = _output.WriteObjectToTempFile("typed parts", result);
+
+ using (var expectedStream = typeof(ParticleTests).GetTypeInfo().Assembly.GetManifestResourceStream("DocumentFormat.OpenXml.Packaging.Tests.data.PartConstraintData.json"))
+ using (var actualStream = new FileStream(output, FileMode.Open, FileAccess.Read))
+ {
+ TestUtility.ValidateJsonFileContentsAreEqual(expectedStream!, actualStream);
+ }
}
public static IEnumerable