1
1
using StrDss . Common . Converters ;
2
+ using System . Text . Json ;
2
3
using System . Text . Json . Serialization ;
3
4
4
5
namespace StrDss . Model
@@ -67,7 +68,8 @@ public class Feature
67
68
public class GeocoderResponse
68
69
{
69
70
public string Type { get ; set ; } = "" ;
70
- public string QueryAddress { get ; set ; } = "" ;
71
+ [ JsonConverter ( typeof ( FlexibleStringConverter ) ) ]
72
+ public string ? QueryAddress { get ; set ; }
71
73
public string SearchTimestamp { get ; set ; }
72
74
public double ExecutionTime { get ; set ; }
73
75
public string Version { get ; set ; } = "" ;
@@ -84,4 +86,23 @@ public class GeocoderResponse
84
86
public string CopyrightLicense { get ; set ; } = "" ;
85
87
public Feature [ ] Features { get ; set ; }
86
88
}
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
+ }
87
108
}
0 commit comments