Skip to content

Commit

Permalink
Migrate from Newtonsoft.Json to System.Text.Json
Browse files Browse the repository at this point in the history
  • Loading branch information
tpetchel committed May 24, 2021
1 parent a00ebdd commit c60ae4c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Tailspin.SpaceGame.Web/LocalDocumentDBRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Text.Json;
using TailSpin.SpaceGame.Web.Models;

namespace TailSpin.SpaceGame.Web
Expand All @@ -17,7 +17,7 @@ public class LocalDocumentDBRepository<T> : IDocumentDBRepository<T> where T : M
public LocalDocumentDBRepository(string fileName)
{
// Serialize the items from the provided JSON document.
_items = JsonConvert.DeserializeObject<List<T>>(File.ReadAllText(fileName));
_items = JsonSerializer.Deserialize<List<T>>(File.ReadAllText(fileName));
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Tailspin.SpaceGame.Web/Models/Model.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace TailSpin.SpaceGame.Web.Models
{
Expand All @@ -8,7 +8,7 @@ namespace TailSpin.SpaceGame.Web.Models
public abstract class Model
{
// The value that uniquely identifies this object.
[JsonProperty(PropertyName = "id")]
[JsonPropertyName("id")]
public string Id { get; set; }
}
}
8 changes: 4 additions & 4 deletions Tailspin.SpaceGame.Web/Models/Profile.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace TailSpin.SpaceGame.Web.Models
{
public class Profile : Model
{
// The player's user name.
[JsonProperty(PropertyName = "userName")]
[JsonPropertyName("userName")]
public string UserName { get; set; }

// The URL of the player's avatar image.
[JsonProperty(PropertyName = "avatarUrl")]
[JsonPropertyName("avatarUrl")]
public string AvatarUrl { get; set; }

// The achievements the player earned.
[JsonProperty(PropertyName = "achievements")]
[JsonPropertyName("achievements")]
public string[] Achievements { get; set; }
}
}
10 changes: 5 additions & 5 deletions Tailspin.SpaceGame.Web/Models/Score.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace TailSpin.SpaceGame.Web.Models
{
public class Score : Model
{
// The ID of the player profile associated with this score.
[JsonProperty(PropertyName = "profileId")]
[JsonPropertyName("profileId")]
public string ProfileId { get; set; }

// The score value.
[JsonProperty(PropertyName = "score")]
[JsonPropertyName("score")]
public int HighScore { get; set; }

// The game mode the score is associated with.
[JsonProperty(PropertyName = "gameMode")]
[JsonPropertyName("gameMode")]
public string GameMode { get; set; }

// The game region (map) the score is associated with.
[JsonProperty(PropertyName = "gameRegion")]
[JsonPropertyName("gameRegion")]
public string GameRegion { get; set; }
}
}
6 changes: 0 additions & 6 deletions Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
<ProjectGuid>{A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}</ProjectGuid>
</PropertyGroup>

<ItemGroup>
<!-- <PackageReference Include="Microsoft.AspNetCore.App" /> -->
<!-- <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" /> -->
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\images\avatars\" />
</ItemGroup>
Expand Down

0 comments on commit c60ae4c

Please sign in to comment.