-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handel changed service metadata json with multiple targets entities (#…
…858)
- Loading branch information
1 parent
7fbcc0f
commit 4b5b3c4
Showing
6 changed files
with
82 additions
and
15 deletions.
There are no files selected for viewing
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
22 changes: 22 additions & 0 deletions
22
...tDaemon.HassModel.CodeGenerator/MetaData/ServicesMetaData/SingleObjectAsArrayConverter.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,22 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace NetDaemon.HassModel.CodeGenerator.Model; | ||
|
||
/// <summary> | ||
/// Converts either a single object or an array to an array | ||
/// </summary> | ||
class SingleObjectAsArrayConverter<T> : JsonConverter<T[]> | ||
{ | ||
public override T[]? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType == JsonTokenType.StartObject) | ||
{ | ||
return new [] { JsonSerializer.Deserialize<T>(ref reader, options)! }; | ||
} | ||
|
||
return JsonSerializer.Deserialize<T[]>(ref reader, options); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, T[] value, JsonSerializerOptions options) | ||
=> throw new NotSupportedException(); | ||
} |
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