Skip to content

Commit

Permalink
Also use LenientGasSerializer for serializing as string (#627)
Browse files Browse the repository at this point in the history
* Also use LenientGasSerializer for serializing as string

* Fix unit test
  • Loading branch information
JoschaMetze authored Dec 10, 2024
1 parent cd9d62f commit 5c6a22e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace BO4E.meta.LenientConverters;
public class LenientGeraetemerkmalGasConverter : JsonConverter
{
/// <inheritdoc cref="JsonConverter.CanWrite" />
public override bool CanWrite => false;
public override bool CanWrite => true;

/// <inheritdoc cref="JsonConverter.CanConvert(Type)" />
public override bool CanConvert(Type objectType)
Expand Down Expand Up @@ -65,6 +65,6 @@ JsonSerializer serializer
/// <inheritdoc cref="JsonConverter.WriteJson(JsonWriter, object, JsonSerializer)" />
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
writer.WriteRawValue("\"" + value.ToString() + "\"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,8 @@ JsonSerializerOptions options
{
if (value.HasValue)
{
// Remove the "GAS_" prefix if it exists
var stringValue = value.Value.ToString();
var match = GasPrefixRegex.Match(stringValue);
if (!match.Success)
{
writer.WriteStringValue(stringValue);
return;
}
var rest = match.Groups["rest"].Value;
writer.WriteStringValue(rest);
var stringValue = value.ToString();
writer.WriteStringValue(stringValue);
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion BO4E/protobuf-files/bo4e.proto
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ enum Energierichtung {
AUSSP = 0;
EINSP = 1;
RUHEND = 2;
KUNDENANLAGE = 3;
}
message Erreichbarkeit {
option (.protobuf_net.msgopt).namespace = "BO4E.COM";
Expand Down Expand Up @@ -966,7 +967,7 @@ message Marktlokation {
Geschaeftspartner Endkunde = 17;
Adresse Lokationsadresse = 18;
Geokoordinaten Geoadresse = 19;
Katasteradresse Katasterinformation = 20;
repeated Katasteradresse Katasterinformation = 20;
repeated Messlokationszuordnung ZugehoerigeMesslokationen = 28;
repeated Netznutzungsabrechnungsdaten Netznutzungsabrechnungsdaten = 37;
Sperrstatus Sperrstatus = 38;
Expand Down
4 changes: 2 additions & 2 deletions BO4ETestProject/TestGeraetemerkmalConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public void TestNewtonsoft_Success_Nullable_Serialization()
{
Converters = new List<Newtonsoft.Json.JsonConverter>()
{
new Newtonsoft.Json.Converters.StringEnumConverter(),
new LenientGeraetemerkmalGasConverter(),
new Newtonsoft.Json.Converters.StringEnumConverter(),
},
}
);
Expand Down Expand Up @@ -265,7 +265,7 @@ public void TestSystemText_Write_Nullable()
Merkmal = Geraetemerkmal.GAS_G2P5,
};
var json = System.Text.Json.JsonSerializer.Serialize(instance, settings);
json.Should().Be("{\"merkmal\":\"G2P5\"}");
json.Should().Be("{\"merkmal\":\"GAS_G2P5\"}");
}

[TestMethod]
Expand Down

0 comments on commit 5c6a22e

Please sign in to comment.