-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace JSON.NET with System.Text.Json (#207)
Co-authored-by: Diogo Trindade <diogotr7@gmail.com>
- Loading branch information
1 parent
1de253c
commit 68f98c3
Showing
10 changed files
with
72 additions
and
48 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/Collections/Artemis.Plugins.PhilipsHue/Models/PhilipsHueBridge.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Collections/Artemis.Plugins.WebAPI/Json/DataModelJsonTypeInfoResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization.Metadata; | ||
using Artemis.Core; | ||
using Artemis.Core.Modules; | ||
|
||
namespace Artemis.Plugins.WebAPI.Json; | ||
|
||
public class DataModelJsonTypeInfoResolver : DefaultJsonTypeInfoResolver | ||
{ | ||
public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options) | ||
{ | ||
JsonTypeInfo jsonTypeInfo = base.GetTypeInfo(type, options); | ||
|
||
if (jsonTypeInfo.Kind == JsonTypeInfoKind.Object) | ||
{ | ||
jsonTypeInfo.Properties.Clear(); | ||
|
||
foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)) | ||
{ | ||
if (propertyInfo.GetCustomAttribute<DataModelIgnoreAttribute>() != null) | ||
continue; | ||
if (propertyInfo.PropertyType.IsAssignableTo(typeof(IDataModelEvent))) | ||
continue; | ||
|
||
JsonPropertyInfo jsonPropertyInfo = jsonTypeInfo.CreateJsonPropertyInfo(propertyInfo.PropertyType, propertyInfo.Name); | ||
jsonPropertyInfo.Get = propertyInfo.CanRead ? propertyInfo.GetValue : null; | ||
jsonPropertyInfo.Set = propertyInfo.CanWrite ? (obj, value) => propertyInfo.SetValue(obj, value) : null; | ||
jsonTypeInfo.Properties.Add(jsonPropertyInfo); | ||
} | ||
} | ||
|
||
return jsonTypeInfo; | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
src/Collections/Artemis.Plugins.WebAPI/Json/DataModelResolver.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,6 @@ public override void Enable() | |
}); | ||
} | ||
|
||
|
||
public override void Disable() | ||
{ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters