Skip to content

Commit 253f243

Browse files
committed
Support JSON in .NET Core 3
2 parents 4c6311d + fed2bb7 commit 253f243

File tree

9 files changed

+51
-10
lines changed

9 files changed

+51
-10
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build/
1111
tools/
1212
Experiment/
1313
Plugins/
14-
14+
.vscode
1515

1616
# User-specific files
1717
*.suo

OData2Poco.CommandLine.Test/ParserTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task Arg_contains_version_Test()
3939
//Act
4040
var result = await RunCommand(args);
4141
//Assert
42-
Assert.That(result.Item2.Split('\n').Length, Is.EqualTo(1));
42+
Assert.That(result.Item2.Split('\n').Length, Is.EqualTo(2)); //commandlinee v2.8 add newline
4343

4444
}
4545

OData2Poco.CommandLine.Test/ProgramTests.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,12 @@ public async Task NullableDatatypeTest(string url, string version, int n)
184184

185185
[Test]
186186
[TestCaseSource(typeof(TestSample), nameof(TestSample.FileCases))]
187+
[Category("json")]
187188
public async Task PocoSettingWithJsonAttributeTest(string url, string version, int n)
188189
{
189190
//Arrange
190-
var a = $"-r {url} -j -v";
191+
// var a = $"-r {url} -j -v"; //obsolete
192+
var a = $"-r {url} -a json -v";
191193
//Act
192194
var tuble = await RunCommand(a);
193195
var output = tuble.Item2;
@@ -201,6 +203,25 @@ public async Task PocoSettingWithJsonAttributeTest(string url, string version, i
201203
Assert.IsTrue(output.Contains("CategoryName"));
202204
}
203205

206+
[Test]
207+
[TestCaseSource(typeof(TestSample), nameof(TestSample.FileCases))]
208+
[Category("json3")]
209+
public async Task PocoSettingWithJsonAttributeNetCore3Test(string url, string version, int n)
210+
{
211+
//Arrange
212+
var a = $"-r {url} -a json3 -v";
213+
//Act
214+
var tuble = await RunCommand(a);
215+
var output = tuble.Item2;
216+
217+
//Assert
218+
Assert.AreEqual(0, tuble.Item1); //exit code
219+
Assert.IsTrue(output.Contains("public partial class Category"));
220+
Assert.IsTrue(output.Contains("[JsonPropertyName(\"CategoryID\")]"));
221+
Assert.IsTrue(output.Contains("Category"));
222+
Assert.IsTrue(output.Contains(" [JsonPropertyName(\"CategoryName\")]"));
223+
Assert.IsTrue(output.Contains("CategoryName"));
224+
}
204225
[Test]
205226
[TestCaseSource(typeof(TestSample), nameof(TestSample.FileCases))]
206227
public async Task PocoSettingWithJsonAttributeAndCamelCaseTest(string url, string version, int n)

OData2Poco.CommandLine/OData2Poco.CommandLine.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</ItemGroup>
2626

2727
<ItemGroup>
28-
<PackageReference Include="CommandLineParser" Version="2.5.0">
28+
<PackageReference Include="CommandLineParser" Version="2.8.0">
2929
<PrivateAssets>All</PrivateAssets>
3030
</PackageReference>
3131
</ItemGroup>

OData2Poco.Core/Options.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class Options
8282
public string EntityNameCase { get; set; }
8383

8484
[Option('a', "attribute",
85-
HelpText = "Attributes, Allowed values: key, req, json,tab,dm,proto,db,display")]
85+
HelpText = "Attributes, Allowed values: key, req, json, json3, tab, dm, proto, db, display")]
8686
public IEnumerable<string> Attributes { get; set; }
8787

8888
// [Option("lang", Default = "cs", HelpText = "Type cs for CSharp, vb for VB.NET")]

OData2Poco.dotnet.o2pgen/OData2Poco.dotnet.o2pgen.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="CommandLineParser" Version="2.5.0" />
32+
<PackageReference Include="CommandLineParser" Version="2.8.0" />
3333
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.2.12-alpha">
3434
<PrivateAssets>all</PrivateAssets>
3535
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>

OData2PocoLib/AssemplyManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void AddAssemply(params string[] list)
5858
{"Req" ,"System.ComponentModel.DataAnnotations"},
5959
{"Table" ,"System.ComponentModel.DataAnnotations.Schema"},
6060
{"json","Newtonsoft.Json"}, //extrnal type can be installed from nuget
61+
{"json3","System.Text.Json.Serialization"}, //netcore 3+
6162
//assemplies for Geographic data type
6263
{"Geometry","Microsoft.Spatial"}, //extrnal type can be installed from nuget
6364
{"Geography", "Microsoft.Spatial"} ,//extrnal type can be installed from nuget
@@ -92,8 +93,9 @@ private void AddAssemplyReferenceList()
9293
if (_pocoSetting.AddTableAttribute) AddAssemplyByKey("table");
9394
if (_pocoSetting.Attributes.Contains("tab")) AddAssemplyByKey("table");
9495

95-
if (_pocoSetting.AddJsonAttribute) AddAssemplyByKey("json");
96+
if (_pocoSetting.AddJsonAttribute) AddAssemplyByKey("json"); //obsolete
9697
if (_pocoSetting.Attributes.Contains("json")) AddAssemplyByKey("json");
98+
if (_pocoSetting.Attributes.Contains("json3")) AddAssemplyByKey("json3"); //netcore 3
9799
if (_pocoSetting.Attributes.Contains("dm")) AddAssemplyByKey("DataMember");
98100
if (_pocoSetting.Attributes.Contains("proto")) AddAssemplyByKey("proto");
99101
AddAssempliesOfDataType();//add assemplies of datatype
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
using OData2Poco.Extensions;
3+
4+
namespace OData2Poco.CustAttributes.NamedAtributes
5+
{
6+
public class Json3Attribute : INamedAttribute
7+
{
8+
public string Name { get; } = "json3";
9+
public List<string> GetAttributes(PropertyTemplate property) =>
10+
string.IsNullOrEmpty(property.OriginalName) || property.OriginalName == property.PropName
11+
? new List<string> { $"[JsonPropertyName({property.PropName.Quote()})]" }
12+
: new List<string>();
13+
14+
public List<string> GetAttributes(ClassTemplate property) => new List<string>();
15+
}
16+
}

ReleaseNotes.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
# OData2Poco.CommandLine
44

55
## (Console: o2pgen / .Net Core: dotnet-o2pgen)
6-
## Version 3.4
7-
**Release Date:** Oct 2, 2020
86

9-
**What is new in 3.4:**
7+
## Version 3.4.1
8+
**Release Date:** Oct 3, 2020
9+
10+
**What is new in 3.4.1:**
11+
- Support JSON in .NET Core 3, PR [#32](https://github.com/moh-hassan/odata2poco/pull/31) fix issue #30
1012
- Update namespace of OData EDM types by @LarsBauer, PR [#31](https://github.com/moh-hassan/odata2poco/pull/31) that fix issue [#30](https://github.com/moh-hassan/odata2poco/issues/30).
1113
- Support nullable reference types in C# 8 in OData2Poco project library.
1214
- Add support to symbolic package snupkg and SourceLink.

0 commit comments

Comments
 (0)