Skip to content

Commit f85c51d

Browse files
authored
Merge pull request #918 from bcgov/bug/DSS-1172
DSS-1172 Error Report: JSON Value Issue
2 parents 79a61bd + fae238d commit f85c51d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

server/StrDss.Model/GeocoderDtos.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using StrDss.Common.Converters;
2+
using System.Text.Json;
23
using System.Text.Json.Serialization;
34

45
namespace StrDss.Model
@@ -67,7 +68,8 @@ public class Feature
6768
public class GeocoderResponse
6869
{
6970
public string Type { get; set; } = "";
70-
public string QueryAddress { get; set; } = "";
71+
[JsonConverter(typeof(FlexibleStringConverter))]
72+
public string? QueryAddress { get; set; }
7173
public string SearchTimestamp { get; set; }
7274
public double ExecutionTime { get; set; }
7375
public string Version { get; set; } = "";
@@ -84,4 +86,23 @@ public class GeocoderResponse
8486
public string CopyrightLicense { get; set; } = "";
8587
public Feature[] Features { get; set; }
8688
}
89+
90+
public class FlexibleStringConverter : JsonConverter<string?>
91+
{
92+
public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
93+
{
94+
return reader.TokenType switch
95+
{
96+
JsonTokenType.String => reader.GetString(),
97+
JsonTokenType.Number => reader.GetDouble().ToString(), // or GetInt64() if you expect integers
98+
JsonTokenType.Null => null,
99+
_ => throw new JsonException()
100+
};
101+
}
102+
103+
public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options)
104+
{
105+
writer.WriteStringValue(value);
106+
}
107+
}
87108
}

0 commit comments

Comments
 (0)