File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
src/Microsoft.AspNetCore.Grpc.JsonTranscoding/Internal/Json
test/Microsoft.AspNetCore.Grpc.JsonTranscoding.Tests/ConverterTests Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ namespace Microsoft.AspNetCore.Grpc.JsonTranscoding.Internal.Json;
10
10
11
11
internal sealed class ValueConverter < TMessage > : SettingsConverterBase < TMessage > where TMessage : IMessage , new ( )
12
12
{
13
+ public override bool HandleNull => true ;
14
+
13
15
public ValueConverter ( JsonContext context ) : base ( context )
14
16
{
15
17
}
Original file line number Diff line number Diff line change @@ -84,6 +84,46 @@ public void RepeatedStrings()
84
84
AssertReadJson < HelloRequest > ( json ) ;
85
85
}
86
86
87
+ [ Fact ]
88
+ public void Struct_NullProperty ( )
89
+ {
90
+ var json = @"{ ""prop"": null }" ;
91
+
92
+ AssertReadJson < Struct > ( json ) ;
93
+ }
94
+
95
+ [ Fact ]
96
+ public void Value_Null ( )
97
+ {
98
+ var json = "null" ;
99
+
100
+ AssertReadJson < Value > ( json ) ;
101
+ }
102
+
103
+ [ Fact ]
104
+ public void Value_Integer ( )
105
+ {
106
+ var json = "1" ;
107
+
108
+ AssertReadJson < Value > ( json ) ;
109
+ }
110
+
111
+ [ Fact ]
112
+ public void Value_String ( )
113
+ {
114
+ var json = @"""string!""" ;
115
+
116
+ AssertReadJson < Value > ( json ) ;
117
+ }
118
+
119
+ [ Fact ]
120
+ public void Value_Boolean ( )
121
+ {
122
+ var json = "true" ;
123
+
124
+ AssertReadJson < Value > ( json ) ;
125
+ }
126
+
87
127
[ Fact ]
88
128
public void DataTypes_DefaultValues ( )
89
129
{
Original file line number Diff line number Diff line change @@ -334,6 +334,23 @@ public void Value_Nested()
334
334
AssertWrittenJson ( helloRequest ) ;
335
335
}
336
336
337
+ [ Fact ]
338
+ public void Struct_NullValue ( )
339
+ {
340
+ var helloRequest = new HelloRequest
341
+ {
342
+ ValueValue = Value . ForStruct ( new Struct
343
+ {
344
+ Fields =
345
+ {
346
+ [ "prop" ] = Value . ForNull ( )
347
+ }
348
+ } )
349
+ } ;
350
+
351
+ AssertWrittenJson ( helloRequest ) ;
352
+ }
353
+
337
354
[ Fact ]
338
355
public void Value_Root ( )
339
356
{
@@ -351,6 +368,14 @@ public void Value_Root()
351
368
AssertWrittenJson ( value ) ;
352
369
}
353
370
371
+ [ Fact ]
372
+ public void Value_Null ( )
373
+ {
374
+ var value = Value . ForNull ( ) ;
375
+
376
+ AssertWrittenJson ( value ) ;
377
+ }
378
+
354
379
[ Fact ]
355
380
public void Struct_Nested ( )
356
381
{
You can’t perform that action at this time.
0 commit comments