Skip to content

Commit 4fca76b

Browse files
committed
Fixed incompatible JSON processing in older versions of .NET (prior to .NET 6.0).
1 parent 8fb506f commit 4fca76b

File tree

7 files changed

+41
-48
lines changed

7 files changed

+41
-48
lines changed

Solidsoft.Reply.Parsers.HighCapacityAidc.Tests/Solidsoft.Reply.Parsers.HighCapacityAidc.Tests.csproj

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFrameworks>net7.0;net6.0;net5.0;net48</TargetFrameworks>
5+
<LangVersion>10.0</LangVersion>
56
<Nullable>enable</Nullable>
67
<ImplicitUsings>enable</ImplicitUsings>
78
</PropertyGroup>
89

910
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
11-
<PackageReference Include="Reqnroll.xUnit" Version="2.2.1" />
12-
<PackageReference Include="xunit" Version="2.9.3" />
13-
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
14-
<PrivateAssets>all</PrivateAssets>
11+
<PackageReference Include="FluentAssertions" Version="[7.1.0]" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[17.6.3]" />
13+
<PackageReference Include="Reqnroll.xUnit" Version="[2.3.0]" />
14+
<PackageReference Include="xunit" Version="[2.4.2]" />
15+
<PackageReference Include="xunit.runner.visualstudio" Version="[2.4.5]">
16+
<PrivateAssets>all</PrivateAssets>
1517
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1618
</PackageReference>
17-
<PackageReference Include="FluentAssertions" Version="[7.1.0]" />
1819
</ItemGroup>
1920

2021
<ItemGroup>

Solidsoft.Reply.Parsers.HighCapacityAidc/ElementStrings/AiTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ IEnumerator IEnumerable.GetEnumerator() =>
632632
/// <returns>The AI table as JSON.</returns>
633633
#pragma warning disable VSSpell001 // Spell Check
634634
public virtual string ToJson() =>
635-
#if NETCOREAPP
635+
#if NET6_0_OR_GREATER
636636
System.Text.Json.JsonSerializer.Serialize(_aiTableEntries);
637637
#else
638638
Newtonsoft.Json.JsonConvert.SerializeObject(_aiTableEntries);

Solidsoft.Reply.Parsers.HighCapacityAidc/ElementStrings/AiTableEntry.cs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// --------------------------------------------------------------------------
2020
namespace Solidsoft.Reply.Parsers.HighCapacityAidc.ElementStrings;
2121

22-
#if NETCOREAPP
22+
#if NET6_0_OR_GREATER
2323
using System.Text.Json.Serialization;
2424
#endif
2525

@@ -74,130 +74,120 @@ internal AiTableEntry(
7474
/// <summary>
7575
/// Gets the AI description.
7676
/// </summary>
77-
#if NETCOREAPP
77+
#if NET6_0_OR_GREATER
7878
[JsonPropertyName("description")]
79-
#endif
8079
[JsonProperty("description")]
81-
#if NETCOREAPP
8280
public string Description { get; init; } = string.Empty;
8381
#else
82+
[JsonProperty("description")]
8483
public string Description { get; private set; } = string.Empty;
8584
#endif
8685

8786
/// <summary>
8887
/// Gets the AI.
8988
/// </summary>
90-
#if NETCOREAPP
89+
#if NET6_0_OR_GREATER
9190
[JsonPropertyName("ai")]
92-
#endif
9391
[JsonProperty("ai")]
94-
#if NETCOREAPP
9592
public string Ai { get; init; } = string.Empty;
9693
#else
94+
[JsonProperty("ai")]
9795
public string Ai { get; private set; } = string.Empty;
9896
#endif
9997

10098
/// <summary>
10199
/// Gets the format specifier for the AI.
102100
/// </summary>
103-
#if NETCOREAPP
101+
#if NET6_0_OR_GREATER
104102
[JsonPropertyName("format")]
105-
#endif
106103
[JsonProperty("format")]
107-
#if NETCOREAPP
108104
public string Format { get; init; } = string.Empty;
109105
#else
106+
[JsonProperty("format")]
110107
public string Format { get; private set; } = string.Empty;
111108
#endif
112109

113110
/// <summary>
114111
/// Gets the AI type, in the context of a Digital Link.
115112
/// </summary>
116-
#if NETCOREAPP
113+
#if NET6_0_OR_GREATER
117114
[JsonPropertyName("type")]
118-
#endif
119115
[JsonProperty("type")]
120-
#if NETCOREAPP
121116
public AiTypes Type { get; init; } = AiTypes.Identifier;
122117
#else
118+
[JsonProperty("type")]
123119
public AiTypes Type { get; private set; } = AiTypes.Identifier;
124120
#endif
125121

126122
/// <summary>
127123
/// Gets a value indicating whether the AI has a predefined length.
128124
/// </summary>
129-
#if NETCOREAPP
125+
#if NET6_0_OR_GREATER
130126
[JsonPropertyName("predefinedLength")]
131-
#endif
132127
[JsonProperty("predefinedLength")]
133-
#if NETCOREAPP
134128
public bool PredefinedLength { get; init; } = false;
135129
#else
130+
[JsonProperty("predefinedLength")]
136131
public bool PredefinedLength { get; private set; } = false;
137132
#endif
138133

139134
/// <summary>
140135
/// Gets a regular expression for validating the AI value.
141136
/// </summary>
142-
#if NETCOREAPP
137+
#if NET6_0_OR_GREATER
143138
[JsonPropertyName("regex")]
144-
#endif
145139
[JsonProperty("regex")]
146-
#if NETCOREAPP
147140
public string Regex { get; init; } = string.Empty;
148141
#else
142+
[JsonProperty("regex")]
149143
public string Regex { get; private set; } = string.Empty;
150144
#endif
151145

152146
/// <summary>
153147
/// Gets the AI data title.
154148
/// </summary>
155-
#if NETCOREAPP
149+
#if NET6_0_OR_GREATER
156150
[JsonPropertyName("title")]
157-
#endif
158151
[JsonProperty("title")]
159-
#if NETCOREAPP
160152
public string? Title { get; init; } = null;
161153
#else
154+
[JsonProperty("title")]
162155
public string? Title { get; private set; }
163156
#endif
164157

165158
/// <summary>
166159
/// Gets the short name for the AI (legacy feature).
167160
/// </summary>
168-
#if NETCOREAPP
161+
#if NET6_0_OR_GREATER
169162
[JsonPropertyName("shortName")]
170-
#endif
171163
[JsonProperty("shortName")]
172-
#if NETCOREAPP
173164
public string? ShortName { get; init; } = null;
174165
#else
166+
[JsonProperty("shortName")]
175167
public string? ShortName { get; private set; }
176168
#endif
177169

178170
/// <summary>
179171
/// Gets the position of the check digit.
180172
/// </summary>
181-
#if NETCOREAPP
173+
#if NET6_0_OR_GREATER
182174
[JsonPropertyName("checkDigitPosition")]
183-
#endif
184175
[JsonProperty("checkDigitPosition")]
185-
#if NETCOREAPP
186176
public CheckDigitPosition? CheckDigitPosition { get; init; } = null;
187177
#else
178+
[JsonProperty("checkDigitPosition")]
188179
public CheckDigitPosition? CheckDigitPosition { get; private set; }
189180
#endif
190181

191182
/// <summary>
192183
/// Gets a list of qualifier AIs (applies only to identifier AIs).
193184
/// </summary>
194-
#if NETCOREAPP
185+
#if NET6_0_OR_GREATER
195186
[JsonPropertyName("qualifiers")]
196-
#endif
197187
[JsonProperty("qualifiers")]
198-
#if NETCOREAPP
199188
public List<string>? Qualifiers { get; init; } = null;
200189
#else
190+
[JsonProperty("qualifiers")]
201191
public List<string>? Qualifiers { get; private set; }
202192
#endif
203193

@@ -207,7 +197,7 @@ internal AiTableEntry(
207197
/// <returns>The AI table entry as JSON.</returns>
208198
#pragma warning disable VSSpell001 // Spell Check
209199
public string ToJson() =>
210-
#if NETCOREAPP
200+
#if NET6_0_OR_GREATER
211201
System.Text.Json.JsonSerializer.Serialize(this);
212202
#else
213203
JsonConvert.SerializeObject(this);

Solidsoft.Reply.Parsers.HighCapacityAidc/ElementStrings/InputProcessingExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static string ConvertParenthesesAIsToFnc1(
102102
dataEnd = input.Length;
103103
}
104104

105-
#if NETCOREAPP
105+
#if NET6_0_OR_GREATER
106106
var rawDataSection = input[dataStart..dataEnd];
107107
#else
108108
var rawDataSection = input.Substring(dataStart, dataEnd - dataStart);
@@ -128,7 +128,7 @@ public static string ConvertParenthesesAIsToFnc1(
128128
var message = string.Format(Resources.Barcodes_009, ai, rawDataSection, length);
129129
throw new BarcodeException(1009, message, false);
130130
}
131-
#if NETCOREAPP
131+
#if NET6_0_OR_GREATER
132132
dataForThisAI = rawDataSection[..length];
133133
#else
134134
dataForThisAI = rawDataSection.Substring(0, length);

Solidsoft.Reply.Parsers.HighCapacityAidc/ElementStrings/PredefinedLengthTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private PredefinedLengthTable() {
131131
/// <param name="key">The AI key.</param>
132132
/// <param name="value">The length of the AI value.</param>
133133
/// <returns>True, if the key was found; otherwise false.</returns>
134-
#if NETCOREAPP
134+
#if NET6_0_OR_GREATER
135135
public bool TryGetValue(string key, [MaybeNullWhen(false)] out int value) => _predefinedLengthTable.TryGetValue(key, out value);
136136
#else
137137
public bool TryGetValue(string key, out int value) => _predefinedLengthTable.TryGetValue(key, out value);

Solidsoft.Reply.Parsers.HighCapacityAidc/Parser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static IBarcode Parse(string data, out string preProcessedData, Preproces
124124
// Remove any trailing CR or LF
125125
while (true) {
126126
if (!string.IsNullOrEmpty(input) &&
127-
#if NETCOREAPP
127+
#if NET6_0_OR_GREATER
128128
(input.EndsWith('\r') || input.EndsWith('\n'))) {
129129
input = input[..^1];
130130
#else

Solidsoft.Reply.Parsers.HighCapacityAidc/Solidsoft.Reply.Parsers.HighCapacityAidc.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net9.0;net8.0;net7.0;net6.0;netstandard2.0</TargetFrameworks>
5-
<LangVersion>13.0</LangVersion>
4+
<TargetFrameworks>net7.0;net6.0;netstandard2.0</TargetFrameworks>
5+
<LangVersion>13.0</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
@@ -17,7 +17,9 @@
1717
<PackageReadmeFile>README.md</PackageReadmeFile>
1818
<PackageTags>barcodes;parser;adc;aidc;15418;15434;gs1;ai;mh10;ansi;di</PackageTags>
1919
<PackageReleaseNotes>
20-
1) Amended parser to strip off additional CRLF characters after pre-processing.
20+
The following changes were made in this release.
21+
22+
1) Fixed incompatible JSON processing in older versions of .NET (prior to .NET 6.0).
2123
</PackageReleaseNotes>
2224
<Description>
2325
A library for parsing high-capacity ADC (Automatic Data Capture) media such as two-dimensional barcodes used in Automatic Identification and Data Capture (AIDC). The library supports the following international standards: ISO/IEC 15418:2016 - Information technology — Automatic identification and data capture techniques — GS1 Application Identifiers and ASC MH10 Data Identifiers and maintenance; ISO/IEC 15434:2019 - Information technology — Automatic identification and data capture techniques — Syntax for high-capacity ADC media.
@@ -26,7 +28,7 @@
2628
--------------
2729
$(PackageReleaseNotes)
2830
</Description>
29-
<Version>1.0.17</Version>
31+
<Version>1.0.18</Version>
3032
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
3133
<NeutralLanguage>en</NeutralLanguage>
3234
<PublishRepositoryUrl>true</PublishRepositoryUrl>

0 commit comments

Comments
 (0)