Skip to content

Commit

Permalink
Update to 0.2.0 for vulnerability fixes; move to .NET Standard 2.0 an…
Browse files Browse the repository at this point in the history
…d latest Newtonsoft.Json.
  • Loading branch information
cerebrate committed May 10, 2023
1 parent dfa4cd4 commit 1aec1b6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 37 deletions.
10 changes: 5 additions & 5 deletions Arkane.Json.Expandos/Arkane.Json.Expandos.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>arkane.snk</AssemblyOriginatorKeyFile>
<Version>0.1.0</Version>
<Version>0.2.0</Version>
<Authors>Alistair J. R. Young</Authors>
<Company>Arkane Systems</Company>
<Description>Newtonsoft.JSON converter making it possible to round-trip type-safe ExpandoObjects.</Description>
<PackageLicenseUrl>https://github.com/arkane-systems/json-expandoobject/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/arkane-systems/json-expandoobject/</PackageProjectUrl>
<RepositoryUrl>https://github.com/arkane-systems/json-expandoobject/</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<PackageTags>json json.net dynamic</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RootNamespace>ArkaneSystems.Json.Expandos</RootNamespace>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="11.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
9 changes: 5 additions & 4 deletions Arkane.Json.Expandos/JsonSerializationExceptionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// Alistair J. R. Young
// Arkane Systems
//
// Copyright Arkane Systems 2012-2017. All rights reserved.
// Copyright Arkane Systems 2012-2023. All rights reserved.
//
// Created: 2017-08-17 5:21 PM
// Created: 2023-05-10 12:40 AM

#endregion

Expand All @@ -32,15 +32,16 @@ public static JsonSerializationException Create ([CanBeNull] this JsonReader rea
// Adapted from https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/JsonPosition.cs

var lineInfo = reader as IJsonLineInfo ;
string path = reader?.Path ;
string message = string.Format (CultureInfo.InvariantCulture, format, args) ;
var path = reader?.Path ;
var message = string.Format (CultureInfo.InvariantCulture, format, args) ;
if (!message.EndsWith (Environment.NewLine, StringComparison.Ordinal))
{
message = message.Trim () ;
if (!message.EndsWith (".", StringComparison.Ordinal))
message += "." ;
message += " " ;
}

message += string.Format (CultureInfo.InvariantCulture, "Path '{0}'", path) ;
if (lineInfo?.HasLineInfo () == true)
message += string.Format (CultureInfo.InvariantCulture,
Expand Down
32 changes: 19 additions & 13 deletions Arkane.Json.Expandos/TypeSafeExpandoObjectConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// Alistair J. R. Young
// Arkane Systems
//
// Copyright Arkane Systems 2012-2017. All rights reserved.
// Copyright Arkane Systems 2012-2023. All rights reserved.
//
// Created: 2017-08-17 5:09 PM
// Created: 2023-05-10 12:40 AM

#endregion

Expand Down Expand Up @@ -52,7 +52,7 @@ private object ReadValue ([NotNull] JsonReader reader, JsonSerializer serializer
if (reader.TokenType.IsPrimitiveToken ())
return reader.Value ;

throw reader.Create (string.Format ("Unexpected token when converting ExpandoObject: {0}", reader.TokenType)) ;
throw reader.Create ($"Unexpected token when converting ExpandoObject: {reader.TokenType}") ;
}
}

Expand All @@ -68,7 +68,7 @@ private object ReadList ([NotNull] JsonReader reader, JsonSerializer serializer)
case JsonToken.Comment:
break ;
default:
object v = this.ReadValue (reader, serializer) ;
var v = this.ReadValue (reader, serializer) ;

list.Add (v) ;
break ;
Expand All @@ -84,25 +84,28 @@ private object ReadObject (JsonReader reader, [NotNull] JsonSerializer serialize
{
if (serializer.TypeNameHandling != TypeNameHandling.None)
{
JObject obj = JObject.Load (reader) ;
var obj = JObject.Load (reader) ;

Type polymorphicType = null ;
var polymorphicTypeString = (string) obj["$type"] ;
Type polymorphicType = null ;
var polymorphicTypeString = (string) obj["$type"] ;
if (polymorphicTypeString != null)
{
if (serializer.TypeNameHandling != TypeNameHandling.None)
{
ReflectionUtils.SplitFullyQualifiedTypeName(polymorphicTypeString, out var typeName, out var assemblyName);
ReflectionUtils.SplitFullyQualifiedTypeName (polymorphicTypeString,
out var typeName,
out var assemblyName) ;
polymorphicType = serializer.SerializationBinder.BindToType (assemblyName, typeName) ;
}

obj.Remove ("$type") ;
}

if ((polymorphicType == null) || (polymorphicType == typeof (ExpandoObject)))
using (JsonReader subReader = obj.CreateReader ())
using (var subReader = obj.CreateReader ())
return this.ReadExpandoObject (subReader, serializer) ;
else
using (JsonReader subReader = obj.CreateReader ())
using (var subReader = obj.CreateReader ())
return serializer.Deserialize (subReader, polymorphicType) ;
}

Expand All @@ -118,12 +121,12 @@ private object ReadExpandoObject ([NotNull] JsonReader reader, JsonSerializer se
switch (reader.TokenType)
{
case JsonToken.PropertyName:
string propertyName = reader.Value.ToString () ;
var propertyName = reader.Value.ToString () ;

if (!reader.Read ())
throw reader.Create ("Unexpected end when reading ExpandoObject.") ;

object v = this.ReadValue (reader, serializer) ;
var v = this.ReadValue (reader, serializer) ;

expandoObject[propertyName] = v ;
break ;
Expand All @@ -147,7 +150,10 @@ public override void WriteJson (JsonWriter writer, object value, JsonSerializer
}

/// <inheritdoc />
public override object ReadJson ([NotNull] JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) =>
public override object ReadJson ([NotNull] JsonReader reader,
Type objectType,
object existingValue,
JsonSerializer serializer) =>
this.ReadValue (reader, serializer) ;

/// <inheritdoc />
Expand Down
25 changes: 13 additions & 12 deletions ExpandosTests/ExpandosTests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" />
<Import Project="..\packages\MSTest.TestAdapter.3.0.2\build\net462\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.3.0.2\build\net462\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ExpandosTests</RootNamespace>
<AssemblyName>ExpandosTests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
Expand All @@ -19,6 +19,7 @@
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -39,13 +40,13 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
<HintPath>..\packages\MSTest.TestFramework.3.0.2\lib\net462\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
<HintPath>..\packages\MSTest.TestFramework.3.0.2\lib\net462\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -56,23 +57,23 @@
<Compile Include="Models.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Arkane.Json.Expandos\Arkane.Json.Expandos.csproj">
<Project>{4FA5DD5B-DF6D-4F7A-B510-F25025859429}</Project>
<Name>Arkane.Json.Expandos</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.3.0.2\build\net462\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.3.0.2\build\net462\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.3.0.2\build\net462\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.3.0.2\build\net462\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" />
<Import Project="..\packages\MSTest.TestAdapter.3.0.2\build\net462\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.3.0.2\build\net462\MSTest.TestAdapter.targets')" />
</Project>
6 changes: 3 additions & 3 deletions ExpandosTests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MSTest.TestAdapter" version="1.1.18" targetFramework="net461" />
<package id="MSTest.TestFramework" version="1.1.18" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
<package id="MSTest.TestAdapter" version="3.0.2" targetFramework="net48" />
<package id="MSTest.TestFramework" version="3.0.2" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
</packages>

0 comments on commit 1aec1b6

Please sign in to comment.