Skip to content

Commit c140324

Browse files
authored
Temporarily revert NJsonSchema v11 changes (#2302)
* Revert "Fix tests for NJsonSchema 11 (#19) (#2291)" This reverts commit bebc802. * Revert "Update NJsonSchema to v11 (#2263)" This reverts commit ef89a01.
1 parent 6e70fbe commit c140324

File tree

10 files changed

+17
-138
lines changed

10 files changed

+17
-138
lines changed

examples/JsonWithReferences/JsonWithReferences.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
55
<AssemblyName>JsonWithReferences</AssemblyName>
66
<OutputType>Exe</OutputType>
7-
<TargetFramework>net8.0</TargetFramework>
7+
<TargetFramework>net6.0</TargetFramework>
88
<LangVersion>7.1</LangVersion>
99
</PropertyGroup>
1010

examples/JsonWithReferences/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
using System.Collections.Generic;
2323
using System.Threading;
2424
using System.Threading.Tasks;
25+
using NJsonSchema.Generation;
2526
using Newtonsoft.Json;
2627
using Newtonsoft.Json.Serialization;
27-
using NJsonSchema.NewtonsoftJson.Generation;
2828

2929

3030
/// <summary>
@@ -150,7 +150,7 @@ static async Task Main(string[] args)
150150
// from default one to camelCase.
151151
// It's also possible to add JsonProperty attributes to customize
152152
// serialization mapping and all available NJson attributes.
153-
var jsonSchemaGeneratorSettings = new NewtonsoftJsonSchemaGeneratorSettings
153+
var jsonSchemaGeneratorSettings = new JsonSchemaGeneratorSettings
154154
{
155155
SerializerSettings = new JsonSerializerSettings
156156
{

src/Confluent.SchemaRegistry.Serdes.Json/Confluent.SchemaRegistry.Serdes.Json.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@
1616
<Title>Confluent.SchemaRegistry.Serdes.Json</Title>
1717
<AssemblyName>Confluent.SchemaRegistry.Serdes.Json</AssemblyName>
1818
<VersionPrefix>2.5.2</VersionPrefix>
19-
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
19+
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
2020
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2121
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2222
<SignAssembly>true</SignAssembly>
2323
<AssemblyOriginatorKeyFile>Confluent.SchemaRegistry.Serdes.Json.snk</AssemblyOriginatorKeyFile>
2424
</PropertyGroup>
2525

26-
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
27-
<PackageReference Include="NJsonSchema.NewtonsoftJson" Version="11.0.2" />
28-
</ItemGroup>
29-
30-
<ItemGroup Condition=" '$(TargetFramework)' != 'net8.0' ">
26+
<ItemGroup>
3127
<PackageReference Include="NJsonSchema" Version="10.9.0" />
3228
</ItemGroup>
3329

src/Confluent.SchemaRegistry.Serdes.Json/JsonDeserializer.cs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@
2525
using Newtonsoft.Json;
2626
using Newtonsoft.Json.Linq;
2727
using NJsonSchema;
28-
#if NET8_0_OR_GREATER
29-
using NJsonSchema.NewtonsoftJson.Generation;
30-
#else
3128
using NJsonSchema.Generation;
32-
#endif
3329
using NJsonSchema.Validation;
3430

3531

@@ -57,11 +53,7 @@ namespace Confluent.SchemaRegistry.Serdes
5753
/// </remarks>
5854
public class JsonDeserializer<T> : AsyncDeserializer<T, JsonSchema> where T : class
5955
{
60-
#if NET8_0_OR_GREATER
61-
private readonly NewtonsoftJsonSchemaGeneratorSettings jsonSchemaGeneratorSettings;
62-
#else
6356
private readonly JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings;
64-
#endif
6557

6658
private JsonSchemaValidator validator = new JsonSchemaValidator();
6759

@@ -77,30 +69,18 @@ public class JsonDeserializer<T> : AsyncDeserializer<T, JsonSchema> where T : cl
7769
/// <param name="jsonSchemaGeneratorSettings">
7870
/// JSON schema generator settings.
7971
/// </param>
80-
#if NET8_0_OR_GREATER
81-
public JsonDeserializer(IEnumerable<KeyValuePair<string, string>> config = null, NewtonsoftJsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null) :
82-
#else
8372
public JsonDeserializer(IEnumerable<KeyValuePair<string, string>> config = null, JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null) :
84-
#endif
8573
this(null, config, jsonSchemaGeneratorSettings)
8674
{
8775
}
8876

89-
#if NET8_0_OR_GREATER
90-
public JsonDeserializer(ISchemaRegistryClient schemaRegistryClient, IEnumerable<KeyValuePair<string, string>> config = null, NewtonsoftJsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null)
91-
#else
92-
public JsonDeserializer(ISchemaRegistryClient schemaRegistryClient, IEnumerable<KeyValuePair<string, string>> config = null, JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null)
93-
#endif
77+
public JsonDeserializer(ISchemaRegistryClient schemaRegistryClient, IEnumerable<KeyValuePair<string, string>> config = null, JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null)
9478
: this(schemaRegistryClient, config != null ? new JsonDeserializerConfig(config) : null, jsonSchemaGeneratorSettings)
9579
{
9680
}
9781

9882
public JsonDeserializer(ISchemaRegistryClient schemaRegistryClient, JsonDeserializerConfig config,
99-
#if NET8_0_OR_GREATER
100-
NewtonsoftJsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null, IList<IRuleExecutor> ruleExecutors = null)
101-
#else
10283
JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null, IList<IRuleExecutor> ruleExecutors = null)
103-
#endif
10484
: base(schemaRegistryClient, config, ruleExecutors)
10585
{
10686
this.jsonSchemaGeneratorSettings = jsonSchemaGeneratorSettings;
@@ -141,12 +121,7 @@ public JsonDeserializer(ISchemaRegistryClient schemaRegistryClient, JsonDeserial
141121
/// JSON schema generator settings.
142122
/// </param>
143123
public JsonDeserializer(ISchemaRegistryClient schemaRegistryClient, Schema schema, IEnumerable<KeyValuePair<string, string>> config = null,
144-
#if NET8_0_OR_GREATER
145-
NewtonsoftJsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null)
146-
#else
147-
JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null)
148-
#endif
149-
: this(schemaRegistryClient, config, jsonSchemaGeneratorSettings)
124+
JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null) : this(schemaRegistryClient, config, jsonSchemaGeneratorSettings)
150125
{
151126
JsonSchemaResolver utils = new JsonSchemaResolver(
152127
schemaRegistryClient, schema, this.jsonSchemaGeneratorSettings);
@@ -231,11 +206,7 @@ public override async Task<T> DeserializeAsync(ReadOnlyMemory<byte> data, bool i
231206
using (var jsonStream = new MemoryStream(array, headerSize, array.Length - headerSize))
232207
using (var jsonReader = new StreamReader(jsonStream, Encoding.UTF8))
233208
{
234-
#if NET8_0_OR_GREATER
235-
JToken json = Newtonsoft.Json.JsonConvert.DeserializeObject<JToken>(jsonReader.ReadToEnd(), this.jsonSchemaGeneratorSettings?.SerializerSettings);
236-
#else
237209
JToken json = Newtonsoft.Json.JsonConvert.DeserializeObject<JToken>(jsonReader.ReadToEnd(), this.jsonSchemaGeneratorSettings?.ActualSerializerSettings);
238-
#endif
239210
json = await ExecuteMigrations(migrations, isKey, subject, topic, context.Headers, json)
240211
.ContinueWith(t => (JToken)t.Result)
241212
.ConfigureAwait(continueOnCapturedContext: false);
@@ -272,11 +243,7 @@ public override async Task<T> DeserializeAsync(ReadOnlyMemory<byte> data, bool i
272243
}
273244
}
274245

275-
#if NET8_0_OR_GREATER
276-
value = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(serializedString, this.jsonSchemaGeneratorSettings?.SerializerSettings);
277-
#else
278246
value = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(serializedString, this.jsonSchemaGeneratorSettings?.ActualSerializerSettings);
279-
#endif
280247
}
281248
}
282249

src/Confluent.SchemaRegistry.Serdes.Json/JsonSchemaResolver.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
using NJsonSchema;
2121
using NJsonSchema.Generation;
2222
using Newtonsoft.Json.Linq;
23-
#if NET8_0_OR_GREATER
24-
using NJsonSchema.NewtonsoftJson.Generation;
25-
#endif
2623

2724

2825
namespace Confluent.SchemaRegistry.Serdes
@@ -115,11 +112,7 @@ private async Task<JsonSchema> GetSchemaUtil(Schema root)
115112
{
116113
NJsonSchema.Generation.JsonSchemaResolver schemaResolver =
117114
new NJsonSchema.Generation.JsonSchemaResolver(rootObject, this.jsonSchemaGeneratorSettings ??
118-
#if NET8_0_OR_GREATER
119-
new NewtonsoftJsonSchemaGeneratorSettings());
120-
#else
121115
new JsonSchemaGeneratorSettings());
122-
#endif
123116

124117
JsonReferenceResolver referenceResolver =
125118
new JsonReferenceResolver(schemaResolver);

src/Confluent.SchemaRegistry.Serdes.Json/JsonSerializer.cs

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@
2424
using System.Net;
2525
using System.Threading.Tasks;
2626
using NJsonSchema;
27+
using NJsonSchema.Generation;
2728
using NJsonSchema.Validation;
2829
using Confluent.Kafka;
29-
#if NET8_0_OR_GREATER
30-
using NJsonSchema.NewtonsoftJson.Generation;
31-
#else
32-
using NJsonSchema.Generation;
33-
#endif
3430

3531

3632
namespace Confluent.SchemaRegistry.Serdes
@@ -58,11 +54,7 @@ namespace Confluent.SchemaRegistry.Serdes
5854
/// </remarks>
5955
public class JsonSerializer<T> : AsyncSerializer<T, JsonSchema> where T : class
6056
{
61-
#if NET8_0_OR_GREATER
62-
private readonly NewtonsoftJsonSchemaGeneratorSettings jsonSchemaGeneratorSettings;
63-
#else
6457
private readonly JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings;
65-
#endif
6658
private readonly List<SchemaReference> ReferenceList = new List<SchemaReference>();
6759

6860
private JsonSchemaValidator validator = new JsonSchemaValidator();
@@ -90,23 +82,14 @@ public class JsonSerializer<T> : AsyncSerializer<T, JsonSchema> where T : class
9082
/// JSON schema generator settings.
9183
/// </param>
9284
public JsonSerializer(ISchemaRegistryClient schemaRegistryClient, JsonSerializerConfig config = null,
93-
#if NET8_0_OR_GREATER
94-
NewtonsoftJsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null, IList<IRuleExecutor> ruleExecutors = null)
95-
#else
9685
JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null, IList<IRuleExecutor> ruleExecutors = null)
97-
#endif
9886
: base(schemaRegistryClient, config, ruleExecutors)
9987
{
10088
this.jsonSchemaGeneratorSettings = jsonSchemaGeneratorSettings;
10189

10290
this.schema = this.jsonSchemaGeneratorSettings == null
103-
#if NET8_0_OR_GREATER
104-
? NewtonsoftJsonSchemaGenerator.FromType<T>()
105-
: NewtonsoftJsonSchemaGenerator.FromType<T>(this.jsonSchemaGeneratorSettings);
106-
#else
10791
? JsonSchema.FromType<T>()
10892
: JsonSchema.FromType<T>(this.jsonSchemaGeneratorSettings);
109-
#endif
11093
this.schemaText = schema.ToJson();
11194
this.schemaFullname = schema.Title;
11295

@@ -153,11 +136,7 @@ public JsonSerializer(ISchemaRegistryClient schemaRegistryClient, JsonSerializer
153136
/// JSON schema generator settings.
154137
/// </param>
155138
public JsonSerializer(ISchemaRegistryClient schemaRegistryClient, Schema schema, JsonSerializerConfig config = null,
156-
#if NET8_0_OR_GREATER
157-
NewtonsoftJsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null, IList<IRuleExecutor> ruleExecutors = null)
158-
#else
159-
JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null, IList<IRuleExecutor> ruleExecutors = null)
160-
#endif
139+
JsonSchemaGeneratorSettings jsonSchemaGeneratorSettings = null, IList<IRuleExecutor> ruleExecutors = null)
161140
: this(schemaRegistryClient, config, jsonSchemaGeneratorSettings, ruleExecutors)
162141
{
163142
foreach (var reference in schema.References)
@@ -175,7 +154,7 @@ public JsonSerializer(ISchemaRegistryClient schemaRegistryClient, Schema schema,
175154

176155
/// <summary>
177156
/// Serialize an instance of type <typeparamref name="T"/> to a UTF8 encoded JSON
178-
/// representation. The serialized data is preceded by:
157+
/// represenation. The serialized data is preceeded by:
179158
/// 1. A "magic byte" (1 byte) that identifies this as a message with
180159
/// Confluent Platform framing.
181160
/// 2. The id of the schema as registered in Confluent's Schema Registry
@@ -190,7 +169,7 @@ public JsonSerializer(ISchemaRegistryClient schemaRegistryClient, Schema schema,
190169
/// Context relevant to the serialize operation.
191170
/// </param>
192171
/// <returns>
193-
/// A <see cref="System.Threading.Tasks.Task" /> that completes with
172+
/// A <see cref="System.Threading.Tasks.Task" /> that completes with
194173
/// <paramref name="value" /> serialized as a byte array.
195174
/// </returns>
196175
public override async Task<byte[]> SerializeAsync(T value, SerializationContext context)
@@ -254,11 +233,7 @@ public override async Task<byte[]> SerializeAsync(T value, SerializationContext
254233
.ConfigureAwait(continueOnCapturedContext: false);
255234
}
256235

257-
#if NET8_0_OR_GREATER
258-
var serializedString = Newtonsoft.Json.JsonConvert.SerializeObject(value, this.jsonSchemaGeneratorSettings?.SerializerSettings);
259-
#else
260236
var serializedString = Newtonsoft.Json.JsonConvert.SerializeObject(value, this.jsonSchemaGeneratorSettings?.ActualSerializerSettings);
261-
#endif
262237
var validationResult = validator.Validate(serializedString, this.schema);
263238
if (validationResult.Count > 0)
264239
{

test/Confluent.SchemaRegistry.Serdes.IntegrationTests/Confluent.SchemaRegistry.Serdes.IntegrationTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
55
<TestProjectType>UnitTest</TestProjectType>
66
<AssemblyName>Confluent.SchemaRegistry.Serdes.IntegrationTests</AssemblyName>
7-
<TargetFramework>net8.0</TargetFramework>
7+
<TargetFramework>net6.0</TargetFramework>
88
</PropertyGroup>
99

1010
<ItemGroup>

test/Confluent.SchemaRegistry.Serdes.IntegrationTests/Tests_Json/UseReferences.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
using Newtonsoft.Json;
2323
using Newtonsoft.Json.Serialization;
2424
using Newtonsoft.Json.Linq;
25-
using NJsonSchema.NewtonsoftJson.Generation;
25+
using NJsonSchema.Generation;
2626

2727

2828
namespace Confluent.SchemaRegistry.Serdes.IntegrationTests
@@ -139,7 +139,7 @@ public static void UseReferences(string bootstrapServers, string schemaRegistryS
139139
var schemaRegistryConfig = new SchemaRegistryConfig { Url = schemaRegistryServers };
140140
var sr = new CachedSchemaRegistryClient(schemaRegistryConfig);
141141

142-
var jsonSchemaGeneratorSettings = new NewtonsoftJsonSchemaGeneratorSettings
142+
var jsonSchemaGeneratorSettings = new JsonSchemaGeneratorSettings
143143
{
144144
SerializerSettings = new JsonSerializerSettings
145145
{
@@ -209,7 +209,7 @@ public static void UseReferences(string bootstrapServers, string schemaRegistryS
209209

210210
// Test producing and consuming directly a JObject
211211
var serializedString = Newtonsoft.Json.JsonConvert.SerializeObject(order,
212-
jsonSchemaGeneratorSettings.SerializerSettings);
212+
jsonSchemaGeneratorSettings.ActualSerializerSettings);
213213
var jsonObject = JObject.Parse(serializedString);
214214

215215
using (var producer =

test/Confluent.SchemaRegistry.Serdes.UnitTests/Confluent.SchemaRegistry.Serdes.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
55
<TestProjectType>UnitTest</TestProjectType>
66
<AssemblyName>Confluent.SchemaRegistry.Serdes.UnitTests</AssemblyName>
7-
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
7+
<TargetFramework>net6.0</TargetFramework>
88
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
99
<SignAssembly>true</SignAssembly>
1010
<AssemblyOriginatorKeyFile>..\..\src\Confluent.SchemaRegistry.Serdes.Protobuf\Confluent.SchemaRegistry.Serdes.Protobuf.snk</AssemblyOriginatorKeyFile>

0 commit comments

Comments
 (0)