Skip to content

Commit

Permalink
Add serializer to calls for management entries and fix minor perf issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Roblinde committed Dec 11, 2023
1 parent 9e2c11e commit 8eee2ea
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 16 deletions.
10 changes: 5 additions & 5 deletions Contentful.AspNetCore/Contentful.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Description>Official .NET SDK for the Contentful Content Delivery and Management API for ASP.NET core.</Description>
<PackageId>contentful.aspnetcore</PackageId>
<NeutralLanguage>en-US</NeutralLanguage>
<VersionPrefix>7.4.3</VersionPrefix>
<VersionPrefix>7.5.0</VersionPrefix>
<TargetFramework>netstandard2.0</TargetFramework>
<Authors>Contentful</Authors>
<Copyright>Contentful GmbH.</Copyright>
Expand All @@ -13,10 +13,10 @@
<PackageProjectUrl>https://github.com/contentful/contentful.net</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<Version>7.4.3</Version>
<AssemblyVersion>7.4.3.0</AssemblyVersion>
<Version>7.5.0</Version>
<AssemblyVersion>7.5.0.0</AssemblyVersion>
<RepositoryUrl>https://github.com/contentful/contentful.net</RepositoryUrl>
<FileVersion>7.4.3.0</FileVersion>
<FileVersion>7.5.0.0</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard1.5\Contentful.AspNetCore.xml</DocumentationFile>
Expand All @@ -25,7 +25,7 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="contentful.csharp" Version="7.4.3" />
<PackageReference Include="contentful.csharp" Version="7.5.0" />
<PackageReference Include="gitlink" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
1 change: 1 addition & 0 deletions Contentful.Core.Tests/ContentfulClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public async Task RateLimitWithRetryShouldRetainQuerystring()
response.Headers.Add("X-Contentful-RateLimit-Reset", "1");

_handler.Response = response;

var qb = QueryBuilder<TestEntryModel>.New.Include(4).Limit(40);
var query = qb.Build();
var numberOfTimesCalled = 0;
Expand Down
24 changes: 21 additions & 3 deletions Contentful.Core.Tests/JsonFiles/SampleEntryManagement.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
"lon": 17.978289127349854
}
},
"field1": {
"en-US": "Somethi"
},
"field1": { "en-US": "Somethi" },
"field4": {
"en-US": {
"sys": {
Expand All @@ -74,6 +72,26 @@
"type": "Link"
}
}
},
"richText": {
"en-US": {
"nodeType": "document",
"data": {},
"content": [
{
"nodeType": "paragraph",
"data": {},
"content": [
{
"nodeType": "text",
"data": {},
"value": "Hello!",
"marks": []
}
]
}
]
}
}
}
}
2 changes: 1 addition & 1 deletion Contentful.Core/Contentful.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PackageId>contentful.csharp</PackageId>
<AssemblyTitle>contentful.net</AssemblyTitle>
<NeutralLanguage>en-US</NeutralLanguage>
<VersionPrefix>7.4.3</VersionPrefix>
<VersionPrefix>7.5.0</VersionPrefix>
<TargetFramework>netstandard2.0</TargetFramework>
<Authors>Contentful</Authors>
<Copyright>Contentful GmbH.</Copyright>
Expand Down
5 changes: 0 additions & 5 deletions Contentful.Core/ContentfulClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ public async Task<ContentfulResult<ContentfulCollection<T>>> GetEntries<T>(strin
return new ContentfulResult<ContentfulCollection<T>>(res.Headers?.ETag?.Tag, null);
}

IEnumerable<T> entries;

var json = JObject.Parse(await res.Content.ReadAsStringAsync().ConfigureAwait(false));

ReplaceMetaData(json);
Expand Down Expand Up @@ -265,10 +263,7 @@ public async Task<ContentfulResult<ContentfulCollection<T>>> GetEntries<T>(strin
grandParent.Add(token.Children());
}

entries = json.SelectToken("$.items").ToObject<IEnumerable<T>>(Serializer);

var collection = json.ToObject<ContentfulCollection<T>>(Serializer);
collection.Items = entries;

collection.IncludedAssets = json.SelectTokens("$.includes.Asset[*]")?.Select(t => t.ToObject<Asset>(Serializer));

Expand Down
5 changes: 3 additions & 2 deletions Contentful.Core/ContentfulManagementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public ContentfulManagementClient(HttpClient httpClient, ContentfulOptions optio
}

SerializerSettings.Converters.Add(new ExtensionJsonConverter());
SerializerSettings.Converters.Add(new ContentJsonConverter());
}

/// <summary>
Expand Down Expand Up @@ -556,7 +557,7 @@ public async Task<T> CreateEntry<T>(T entry, string contentTypeId, string spaceI
};

var createdEntry = await CreateEntry(entryToCreate, contentTypeId, spaceId, cancellationToken);
return (createdEntry.Fields as JObject).ToObject<T>();
return (createdEntry.Fields as JObject).ToObject<T>(Serializer);
}

/// <summary>
Expand Down Expand Up @@ -608,7 +609,7 @@ public async Task<T> CreateOrUpdateEntry<T>(T entry, string id, string spaceId =
};

var createdEntry = await CreateOrUpdateEntry(entryToCreate, spaceId, contentTypeId, version, cancellationToken);
return (createdEntry.Fields as JObject).ToObject<T>();
return (createdEntry.Fields as JObject).ToObject<T>(Serializer);
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions Contentful.Core/Models/AuthoringModels.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Contentful.Core.Models.Management;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -87,6 +88,7 @@ public class HyperlinkData
/// <summary>
/// The title of the hyperlink.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Title { get; set; }
}

Expand Down

0 comments on commit 8eee2ea

Please sign in to comment.