-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Lots of Model Classes; Introduce Json Converters to 100% match th…
…e example files (#2) * Stricter Serialization Tests (WIP) * wip * Use System.Text.Json 9.0.0-rc2 so that we get the JsonStringEnumMemberNameAttribute https://stackoverflow.com/a/78976451/10009545 * wip * wip * don't include sub-seconds * don't include sub-seconds 2 * wip * wip * fix everything * remove BOM * remove settings * remove settings 2 * Update README.md * Fix code style issues with Prettier * empty commit --------- Co-authored-by: Konstantin <[email protected]> Co-authored-by: Lint Action <[email protected]>
- Loading branch information
1 parent
a628280
commit 5f458ca
Showing
41 changed files
with
764 additions
and
402 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=827b5381_002Db4e6_002D437e_002D91f5_002D76b43760d70c/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="Test_Request" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
 | ||
<Project Location="C:\github\malo-ident-net-models\MaLoIdentModels\MaLoIdentModelsTests" Presentation="&lt;MaLoIdentModelsTests&gt;" />
 | ||
</SessionState></s:String> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=fd8f61c1_002D7fe3_002D4070_002D8bfa_002Da09488ff5b82/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Test_Request #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
 | ||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AJsonConverterOfT_002EReadCore_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FKleinKonstantin_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fa7e99f3da3fc9d80c1949ce87d548d992a745092d1c720f44952dbbd144437f_003FJsonConverterOfT_002EReadCore_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=90afe6a5_002D332c_002D4da1_002Da8d5_002D747550c45ccf/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &lt;MaLoIdentModelsTests&gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
 | ||
<Project Location="C:\github\malo-ident-net-models\MaLoIdentModels\MaLoIdentModelsTests" Presentation="&lt;MaLoIdentModelsTests&gt;" />
 | ||
</SessionState></s:String></wpf:ResourceDictionary> |
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,27 @@ | ||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. | ||
namespace MaLoIdentModels; | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
using System.Text.Json.Serialization; | ||
|
||
public class Address | ||
{ | ||
[JsonPropertyName("countryCode")] | ||
[RegularExpression(@"[A-Z]{2}")] | ||
public string CountryCode { get; set; } | ||
|
||
[JsonPropertyName("zipCode")] | ||
public string ZipCode { get; set; } | ||
|
||
[JsonPropertyName("city")] | ||
public string City { get; set; } | ||
|
||
[JsonPropertyName("street")] | ||
public string Street { get; set; } | ||
|
||
[JsonPropertyName("houseNumber")] | ||
public int HouseNumber { get; set; } | ||
|
||
[JsonPropertyName("houseNumberAddition")] | ||
public string HouseNumberAddition { get; set; } | ||
} |
13 changes: 13 additions & 0 deletions
13
MaLoIdentModels/MaLoIdentModels/DataControllableResource.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,13 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MaLoIdentModels; | ||
|
||
public class DataControllableResource | ||
{ | ||
[JsonPropertyName("srId")] | ||
public string? SrId { get; set; } | ||
|
||
[JsonPropertyName("dataControllableResourceMeasuringPointOperators")] | ||
public List<SrMarketPartner>? DataControllableResourceMeasuringPointOperators { get; set; } | ||
} |
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,49 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MaLoIdentModels; | ||
|
||
public class DataMarketLocation | ||
{ | ||
[JsonPropertyName("maloId")] | ||
public string? MaloId { get; set; } | ||
|
||
[JsonPropertyName("energyDirection")] | ||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
public EnergyDirection EnergyDirection { get; set; } | ||
|
||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
[JsonPropertyName("measurementTechnologyClassification")] | ||
public MeasurementTechnologyClassification MeasurementTechnologyClassification { get; set; } | ||
|
||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
[JsonPropertyName("optionalChangeForecastBasis")] | ||
public OptionalChangeForecastBasis OptionalChangeForecastBasis { get; set; } | ||
|
||
[JsonPropertyName("dataMarketLocationProperties")] | ||
public List<MarketLocationProperties>? DataMarketLocationProperties { get; set; } | ||
|
||
[JsonPropertyName("dataMarketLocationNetworkOperators")] | ||
public List<MarketLocationNetworkOperator>? DataMarketLocationNetworkOperators { get; set; } | ||
|
||
[JsonPropertyName("dataMarketLocationMeasuringPointOperators")] | ||
public List<MarketLocationMeasuringPointOperator>? DataMarketLocationMeasuringPointOperators { get; set; } | ||
|
||
[JsonPropertyName("dataMarketLocationTransmissionSystemOperators")] | ||
public List<MarketLocationTransmissionSystemOperator>? DataMarketLocationTransmissionSystemOperators { get; set; } | ||
|
||
[JsonPropertyName("dataMarketLocationSuppliers")] | ||
public List<MarketLocationSupplier>? DataMarketLocationSuppliers { get; set; } | ||
|
||
[JsonPropertyName("dataMarketLocationName")] | ||
public Name? DataMarketLocationName { get; set; } | ||
|
||
[JsonPropertyName("dataMarketLocationAddress")] | ||
public Address? DataMarketLocationAddress { get; set; } | ||
|
||
[JsonPropertyName("dataMarketLocationLandParcels")] | ||
public List<LandParcel>? DataMarketLocationLandParcels { get; set; } | ||
|
||
[JsonPropertyName("dataMarketLocationGeographicCoordinates")] | ||
public GeographicCoordinates? DataMarketLocationGeographicCoordinates { get; set; } | ||
} |
19 changes: 19 additions & 0 deletions
19
MaLoIdentModels/MaLoIdentModels/DataMarketLocationProperties.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,19 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
using MaLoIdentModels.JsonSettings; | ||
|
||
namespace MaLoIdentModels; | ||
|
||
public class DataMarketLocationProperties | ||
{ | ||
[JsonPropertyName("marketLocationProperty")] | ||
public MarketLocationProperty MarketLocationProperty { get; set; } | ||
|
||
[JsonConverter(typeof(DateTimeOffsetWithTrailingZConverter))] | ||
[JsonPropertyName("executionTimeFrom")] | ||
public DateTimeOffset ExecutionTimeFrom { get; set; } | ||
|
||
[JsonConverter(typeof(NullableDateTimeOffsetWithTrailingZConverter))] | ||
[JsonPropertyName("executionTimeUntil")] | ||
public DateTimeOffset? ExecutionTimeUntil { get; set; } | ||
} |
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,16 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MaLoIdentModels; | ||
|
||
public class DataMeterLocation | ||
{ | ||
[JsonPropertyName("meloId")] | ||
public string? MeloId { get; set; } | ||
|
||
[JsonPropertyName("meterNumber")] | ||
public string? MeterNumber { get; set; } | ||
|
||
[JsonPropertyName("dataMeterLocationMeasuringPointOperators")] | ||
public List<MeterLocationMeasuringPointOperator>? DataMeterLocationMeasuringPointOperators { get; set; } | ||
} |
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,13 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MaLoIdentModels; | ||
|
||
public class DataNetworkLocation | ||
{ | ||
[JsonPropertyName("neloId")] | ||
public string? NeloId { get; set; } | ||
|
||
[JsonPropertyName("dataNetworkLocationMeasuringPointOperators")] | ||
public List<NetworkLocationMeasuringPointOperator>? DataNetworkLocationMeasuringPointOperators { get; set; } | ||
} |
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,9 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MaLoIdentModels; | ||
|
||
public class DataTechnicalResource | ||
{ | ||
[JsonPropertyName("trId")] | ||
public string? TrId { get; set; } | ||
} |
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,20 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MaLoIdentModels; | ||
|
||
public class DataTranche | ||
{ | ||
[JsonPropertyName("tranchenId")] | ||
public string? TranchenId { get; set; } | ||
|
||
[JsonPropertyName("proportion")] | ||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
public Proportion Proportion { get; set; } | ||
|
||
[JsonPropertyName("percent")] | ||
public decimal? Percent { get; set; } | ||
|
||
[JsonPropertyName("dataTrancheSuppliers")] | ||
public List<TrancheSupplier>? DataTrancheSuppliers { get; set; } | ||
} |
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,15 @@ | ||
using System.Runtime.Serialization; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MaLoIdentModels; | ||
|
||
public enum EnergyDirection | ||
{ | ||
[EnumMember(Value = "consumption")] | ||
[JsonStringEnumMemberName("consumption")] | ||
Consumption, | ||
|
||
[EnumMember(Value = "production")] | ||
[JsonStringEnumMemberName("production")] | ||
Production, | ||
} |
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,28 @@ | ||
using System.Text.Json.Serialization; | ||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. | ||
namespace MaLoIdentModels; | ||
|
||
public class GeographicCoordinates | ||
{ | ||
[JsonPropertyName("latitude")] | ||
public string Latitude { get; set; } | ||
|
||
[JsonPropertyName("longitude")] | ||
public string Longitude { get; set; } | ||
|
||
[JsonPropertyName("east")] | ||
public string East { get; set; } | ||
|
||
[JsonPropertyName("north")] | ||
public string North { get; set; } | ||
|
||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
[JsonPropertyName("zone")] | ||
public Zone? Zone { get; set; } | ||
|
||
[JsonPropertyName("northing")] | ||
public string Northing { get; set; } | ||
|
||
[JsonPropertyName("easting")] | ||
public string Easting { get; set; } | ||
} |
22 changes: 22 additions & 0 deletions
22
MaLoIdentModels/MaLoIdentModels/IdentificationParameter.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; | ||
using System.Text.Json.Serialization; | ||
using MaLoIdentModels.JsonSettings; | ||
|
||
namespace MaLoIdentModels; | ||
|
||
public class IdentificationParameter | ||
{ | ||
[JsonConverter(typeof(DateTimeOffsetWithTrailingZConverter))] | ||
[JsonPropertyName("identificationDateTime")] | ||
public DateTimeOffset IdentificationDateTime { get; set; } | ||
|
||
[JsonPropertyName("energyDirection")] | ||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
public EnergyDirection EnergyDirection { get; set; } | ||
|
||
[JsonPropertyName("identificationParameterId")] | ||
public IdentificationParameterIdentificationParameterId? IdentificationParameterId { get; set; } | ||
|
||
[JsonPropertyName("identificationParameterAddress")] | ||
public IdentificationParameterIdentificationParameterAddress? IdentificationParameterAddress { get; set; } | ||
} |
19 changes: 19 additions & 0 deletions
19
MaLoIdentModels/MaLoIdentModels/IdentificationParameterIdentificationParameterAddress.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,19 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MaLoIdentModels; | ||
|
||
public class IdentificationParameterIdentificationParameterAddress | ||
{ | ||
[JsonPropertyName("name")] | ||
public Name? Name { get; set; } | ||
|
||
[JsonPropertyName("address")] | ||
public Address? Address { get; set; } | ||
|
||
[JsonPropertyName("landParcels")] | ||
public List<LandParcel>? LandParcels { get; set; } | ||
|
||
[JsonPropertyName("geographicCoordinates")] | ||
public GeographicCoordinates? GeographicCoordinates { get; set; } | ||
} |
22 changes: 22 additions & 0 deletions
22
MaLoIdentModels/MaLoIdentModels/IdentificationParameterIdentificationParameterId.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.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MaLoIdentModels; | ||
|
||
public class IdentificationParameterIdentificationParameterId | ||
{ | ||
[JsonPropertyName("maloId")] | ||
public string? MaloId { get; set; } | ||
|
||
[JsonPropertyName("tranchenIds")] | ||
public List<string>? TranchenIds { get; set; } | ||
|
||
[JsonPropertyName("meloIds")] | ||
public List<string>? MeloIds { get; set; } | ||
|
||
[JsonPropertyName("meterNumbers")] | ||
public List<string>? MeterNumbers { get; set; } | ||
|
||
[JsonPropertyName("customerNumber")] | ||
public string? CustomerNumber { get; set; } | ||
} |
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
MaLoIdentModels/MaLoIdentModels/JsonSettings/DateTimeOffsetWithTrailingZConverter.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,31 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MaLoIdentModels.JsonSettings; | ||
|
||
/// <summary> | ||
/// A JsonConverter that ensures, that we serialize DateTimeOffsets with the "Z" suffix as required by Edi@Enery. | ||
/// A plain '+00:00' is not sufficient. | ||
/// </summary> | ||
public class DateTimeOffsetWithTrailingZConverter : JsonConverter<DateTimeOffset> | ||
{ | ||
public override DateTimeOffset Read( | ||
ref Utf8JsonReader reader, | ||
Type typeToConvert, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
return DateTimeOffset.Parse(reader.GetString()!); | ||
} | ||
|
||
public override void Write( | ||
Utf8JsonWriter writer, | ||
DateTimeOffset value, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
// Always convert the DateTimeOffset to UTC and use the "Z" suffix | ||
writer.WriteStringValue(value.UtcDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ")); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
MaLoIdentModels/MaLoIdentModels/JsonSettings/NullableDateTimeOffsetWithTrailingZConverter.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,43 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MaLoIdentModels.JsonSettings; | ||
|
||
/// <summary> | ||
/// Similar to <see cref="JsonSettings.DateTimeOffsetWithTrailingZConverter"/> but for nullable DateTimeOffsets. | ||
/// </summary> | ||
public class NullableDateTimeOffsetWithTrailingZConverter : JsonConverter<DateTimeOffset?> | ||
{ | ||
public override DateTimeOffset? Read( | ||
ref Utf8JsonReader reader, | ||
Type typeToConvert, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
// Handle deserialization: if the value is null, return null | ||
if (reader.TokenType == JsonTokenType.Null) | ||
{ | ||
return null; | ||
} | ||
|
||
// Parse the input string to a DateTimeOffset | ||
return DateTimeOffset.Parse(reader.GetString()!); | ||
} | ||
|
||
public override void Write( | ||
Utf8JsonWriter writer, | ||
DateTimeOffset? value, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
if (value.HasValue) | ||
{ | ||
writer.WriteStringValue(value.Value.UtcDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ")); | ||
} | ||
else | ||
{ | ||
writer.WriteNullValue(); | ||
} | ||
} | ||
} |
Oops, something went wrong.