Skip to content

Commit

Permalink
Upgrade Newtonsoft.Json to v13.0.2. | Continue Development for JsonAp…
Browse files Browse the repository at this point in the history
…iSerializer (#145)

* fix deprecated licenseUrl and replace with license string

* update newtonsoft.json to latest stable and update target frameworks accordingly

* upgrade dependencies to the latest version and bump target frameworks

* fix wrong target framework for unit tests

* target netstandard2.0 to ensure compatibility with .net framework 4.6.1+ as well as .NET 6+

* set the default c# to 7.3 for improved backwards compatibility with .net framework

* fix typos and missing references in comments and doc blocks

* remove unused or unnecessary using statements

* replace MemberConverter with Converter

* Bump major version number

---------

Co-authored-by: wavedeck <[email protected]>
Co-authored-by: Alex Davies <[email protected]>
  • Loading branch information
3 people authored Apr 19, 2024
1 parent 3c40981 commit 48cdec1
Show file tree
Hide file tree
Showing 25 changed files with 68 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using JsonApiSerializer.JsonApi;
using JsonApiSerializer.JsonApi.WellKnown;
using JsonApiSerializer.JsonConverters;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Serialization;

namespace JsonApiSerializer.ContractResolvers.Contracts
{
Expand All @@ -31,7 +24,7 @@ public JsonObjectContractWrap(JsonObjectContract jsonObjectContract)
ItemReferenceLoopHandling = jsonObjectContract.ItemReferenceLoopHandling;
ItemTypeNameHandling = jsonObjectContract.ItemTypeNameHandling;

//poulate JsonContract fields
//populate JsonContract fields
CreatedType = jsonObjectContract.CreatedType;
IsReference = jsonObjectContract.IsReference;
Converter = jsonObjectContract.Converter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using JsonApiSerializer.JsonApi;
using JsonApiSerializer.JsonApi.WellKnown;
using JsonApiSerializer.JsonConverters;
using JsonApiSerializer.JsonApi.WellKnown;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JsonApiSerializer.ContractResolvers.Contracts
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using JsonApiSerializer.JsonApi;
using JsonApiSerializer.JsonApi.WellKnown;
using JsonApiSerializer.JsonApi.WellKnown;
using JsonApiSerializer.JsonConverters;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JsonApiSerializer.ContractResolvers.Contracts
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using JsonApiSerializer.JsonApi;
using JsonApiSerializer.JsonApi.WellKnown;
using JsonApiSerializer.JsonConverters;
using JsonApiSerializer.JsonApi.WellKnown;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JsonApiSerializer.ContractResolvers.Contracts
{
Expand Down
1 change: 0 additions & 1 deletion src/JsonApiSerializer/JsonApi/Links.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace JsonApiSerializer.JsonApi
/// <summary>
/// Represents a set of links.
/// </summary>
/// <seealso cref="System.Collections.Generic.Dictionary{System.String, JsonApiSerializer.JsonApi.Link}" />
public class Links : Dictionary<string, Link>
{
}
Expand Down
1 change: 0 additions & 1 deletion src/JsonApiSerializer/JsonApi/Meta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace JsonApiSerializer.JsonApi
/// <summary>
/// Represents generic MetaData.
/// </summary>
/// <seealso cref="System.Collections.Generic.Dictionary{System.String, Newtonsoft.Json.Linq.JToken}" />
public class Meta : Dictionary<string, JToken>
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiSerializer/JsonApi/ResourceIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ResourceIdentifier
/// <summary>
/// Creates a Relationship for a given type.
/// </summary>
/// <typeparam name="TData">The type of the data.</typeparam>
/// <typeparam name="TResourceObject">The type of the data.</typeparam>
public static ResourceIdentifier<TResourceObject> Create<TResourceObject>(TResourceObject resourceObject)
{
return new ResourceIdentifier<TResourceObject>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace JsonApiSerializer.JsonApi.WellKnown
namespace JsonApiSerializer.JsonApi.WellKnown
{
interface IResourceIdentifier<TResourceObject>
{
Expand Down
14 changes: 7 additions & 7 deletions src/JsonApiSerializer/JsonApiSerializer.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.0;netstandard1.5;net45</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>7.3</LangVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.7.4</Version>
<Version>2.0.0</Version>
<Authors>Alex Davies</Authors>
<Company>Codecutout</Company>
<Description>JsonApiSerializer supports configurationless serializing and deserializing objects into the json:api format (http://jsonapi.org).</Description>
<PackageLicenseUrl>https://github.com/codecutout/JsonApiSerializer/blob/master/LICENSE</PackageLicenseUrl>
<PackageLicense>MIT</PackageLicense>
<PackageProjectUrl>https://github.com/codecutout/JsonApiSerializer</PackageProjectUrl>
<PackageTags>jsonapiserializer jsonapi json:api json.net serialization deserialization jsonapi.net</PackageTags>
<AssemblyVersion>1.7.4.0</AssemblyVersion>
<FileVersion>1.7.4.0</FileVersion>
<PackageReleaseNotes>Fixed issue that would cuase stackoverflow errors when handling circular references when `included` section is present before `data`</PackageReleaseNotes>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions src/JsonApiSerializer/JsonConverters/ErrorConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

Expand All @@ -24,7 +23,7 @@ public override bool CanConvert(Type objectType)

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
//we may be starting the deserialization here, if thats the case we need to resolve this object as the root
//we may be starting the deserialization here, if that's the case we need to resolve this object as the root
var serializationData = SerializationData.GetSerializationData(reader);
if (!serializationData.HasProcessedDocumentRoot)
{
Expand Down
3 changes: 1 addition & 2 deletions src/JsonApiSerializer/JsonConverters/ErrorListConverter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JsonApiSerializer.JsonApi.WellKnown;
using JsonApiSerializer.SerializationState;
using JsonApiSerializer.Util;
using Newtonsoft.Json;
Expand All @@ -23,7 +22,7 @@ public override bool CanConvert(Type objectType)

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
//we may be starting the deserialization here, if thats the case we need to resolve this object as the root
//we may be starting the deserialization here, if that's the case we need to resolve this object as the root
var serializationData = SerializationData.GetSerializationData(reader);
if (!serializationData.HasProcessedDocumentRoot)
{
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiSerializer/JsonConverters/IncludedConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist

if (!serializationData.Included.TryGetValue(reference, out var existingObject))
{
//we dont know what type this object should be so we will just save it as a JObject
//we don't know what type this object should be so we will just save it as a JObject
var unknownObject = serializer.Deserialize<JObject>(forkableReader);
serializationData.Included.Add(reference, unknownObject);
return unknownObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;

namespace JsonApiSerializer.JsonConverters
{
Expand Down Expand Up @@ -73,7 +72,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
throw new JsonApiFormatException(
writer.Path,
$"Expected to find a resource identifier or resource object, but found '{value}'",
"Resource indentifier objects MUST contain 'id' members");
"Resource identifier objects MUST contain 'id' members");
}

}
Expand Down Expand Up @@ -214,7 +213,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
throw new JsonApiFormatException(
forkableReader.FullPath,
$"Expected to find a resource identifier or resource object, but found '{objectType}'",
"Resource indentifier objects MUST contain 'id' members");
"Resource identifier objects MUST contain 'id' members");
}
}

Expand Down Expand Up @@ -250,7 +249,7 @@ private object ReadJsonAsExplicitResourceIdentifier(ForkableJsonReader reader, T
serializer);

//we will only set the resource object if we have rendered the included
//value somehwere, if we have not it means the value was actaully provided
//value somewhere, if we have not it means the value was actually provided
var valueProvider = resourceIdentifierContract.ResourceObjectProperty.ValueProvider;
serializationData.PostProcessingActions.Add(() =>
{
Expand Down
43 changes: 19 additions & 24 deletions src/JsonApiSerializer/JsonConverters/ResourceObjectConverter.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
using JsonApiSerializer.ContractResolvers;
using JsonApiSerializer.ContractResolvers.Contracts;
using JsonApiSerializer.Exceptions;
using JsonApiSerializer.JsonApi;
using JsonApiSerializer.JsonApi.WellKnown;
using JsonApiSerializer.JsonConverters;
using JsonApiSerializer.SerializationState;
using JsonApiSerializer.Util;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;

namespace JsonApiSerializer.JsonConverters
Expand Down Expand Up @@ -47,7 +42,7 @@ public override bool CanConvert(Type objectType)

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
//we may be starting the deserialization here, if thats the case we need to resolve this object as the root
//we may be starting the deserialization here, if that's the case we need to resolve this object as the root
var serializationData = SerializationData.GetSerializationData(reader);
if (!serializationData.HasProcessedDocumentRoot)
return DocumentRootConverter.ResolveAsRootData(reader, objectType, serializer);
Expand All @@ -67,11 +62,11 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist

var reference = ReaderUtil.ReadAheadToIdentifyObject(forkableReader);

//if we dont have this object already we will create it
//if we don't have this object already we will create it
existingValue = existingValue ?? CreateObject(objectType, reference.Type, serializer);


//mark this object as a possible include. We need to do this before deserialiazing
//mark this object as a possible include. We need to do this before deserializing
//the relationship; It could have relationships that reference back to this object
serializationData.Included[reference] = existingValue;

Expand Down Expand Up @@ -115,14 +110,14 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
continue;

// This is a massive hack. MemberConverters used to work and allowed
// modifying a members create object. Unfortunatly Resource Identifiers
// modifying a members create object. Unfortunately Resource Identifiers
// are no longer created by this object converter. We are passing the
// convertor via the serialization data so ResourceIdentifierConverter
// can access it down the line.
// next breaking change remove support for ResourceObjectConverter
// member converters
if (prop.MemberConverter != null)
serializationData.ConverterStack.Push(prop.MemberConverter);
if (prop.Converter != null)
serializationData.ConverterStack.Push(prop.Converter);

ReaderUtil.TryPopulateProperty(
serializer,
Expand All @@ -131,7 +126,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
reader,
overrideConverter: contractResolver.ResourceRelationshipConverter);

if (prop.MemberConverter != null)
if (prop.Converter != null)
serializationData.ConverterStack.Pop();
}
}
Expand Down Expand Up @@ -165,7 +160,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
throw new JsonApiFormatException(
writer.Path,
$"Expected to find to find resource object, but found '{value}'",
"Resource indentifier objects MUST contain 'id' members");
"Resource identifier objects MUST contain 'id' members");

serializationData.ConverterStack.Push(this);

Expand Down Expand Up @@ -200,7 +195,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s

// store all the relationships, that appear to be attributes from the
// property declared type, types but the runtime type shows they are
// actaully relationships
// actually relationships
List<KeyValuePair<JsonProperty, object>> undeclaredRelationships = null;

//serialize attributes
Expand All @@ -210,12 +205,12 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
var attributeProperty = metadata.Attributes[i];
if (WriterUtil.ShouldWriteProperty(value, attributeProperty, serializer, out object attributeValue))
{
// some relationships are not decalred as such. They exist in properties
// some relationships are not declared as such. They exist in properties
// with declared types of `object` but the runtime object within is a
// relationship. We will check here if this attribute property is really
// a relationship, and if it is store it to process later

// NOTE: this behviour it leads to nulls being inconsistantly attribute/relationship.
// NOTE: this behaviour it leads to nulls being inconsistently attribute/relationship.
// leaving in for backward compatability but remove on next breaking change
var attributeValueType = attributeValue?.GetType();
if (attributeValueType != null
Expand All @@ -235,9 +230,9 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
writer.WriteStartObject();
}
writer.WritePropertyName(attributeProperty.PropertyName);
if (attributeProperty.MemberConverter?.CanWrite == true)
if (attributeProperty.Converter?.CanWrite == true)
{
attributeProperty.MemberConverter.WriteJson(writer, attributeValue, serializer);
attributeProperty.Converter.WriteJson(writer, attributeValue, serializer);
}
else if (attributeValue is string attributeString)
{
Expand Down Expand Up @@ -275,8 +270,8 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
writer.WriteStartObject();
}

if (relationshipProperty.MemberConverter != null)
serializationData.ConverterStack.Push(relationshipProperty.MemberConverter);
if (relationshipProperty.Converter != null)
serializationData.ConverterStack.Push(relationshipProperty.Converter);

writer.WritePropertyName(relationshipProperty.PropertyName);
jsonApiContractResolver.ResourceRelationshipConverter.WriteNullableJson(
Expand All @@ -285,7 +280,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
relationshipValue,
serializer);

if (relationshipProperty.MemberConverter != null)
if (relationshipProperty.Converter != null)
serializationData.ConverterStack.Pop();

}
Expand All @@ -303,8 +298,8 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
writer.WriteStartObject();
}

if (relationshipProperty.MemberConverter != null)
serializationData.ConverterStack.Push(relationshipProperty.MemberConverter);
if (relationshipProperty.Converter != null)
serializationData.ConverterStack.Push(relationshipProperty.Converter);

writer.WritePropertyName(relationshipProperty.PropertyName);
jsonApiContractResolver.ResourceRelationshipConverter.WriteNullableJson(
Expand All @@ -313,7 +308,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
relationshipValue,
serializer);

if (relationshipProperty.MemberConverter != null)
if (relationshipProperty.Converter != null)
serializationData.ConverterStack.Pop();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using JsonApiSerializer.ContractResolvers;
using JsonApiSerializer.ContractResolvers.Contracts;
using JsonApiSerializer.ContractResolvers.Contracts;
using JsonApiSerializer.Exceptions;
using JsonApiSerializer.JsonApi.WellKnown;
using JsonApiSerializer.SerializationState;
using JsonApiSerializer.Util;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace JsonApiSerializer.JsonConverters
{
Expand Down
Loading

0 comments on commit 48cdec1

Please sign in to comment.