Commit c9be1cf 1 parent 9cf6b4a commit c9be1cf Copy full SHA for c9be1cf
File tree 2 files changed +30
-9
lines changed
src/NATS.Client.JetStream/Models
tests/NATS.Client.JetStream.Tests
2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -10,15 +10,8 @@ public record Placement
10
10
/// The desired cluster name to place the stream
11
11
/// </summary>
12
12
[ System . Text . Json . Serialization . JsonPropertyName ( "cluster" ) ]
13
- [ System . Text . Json . Serialization . JsonIgnore ( Condition = System . Text . Json . Serialization . JsonIgnoreCondition . Never ) ]
14
- [ System . ComponentModel . DataAnnotations . Required ( AllowEmptyStrings = true ) ]
15
- #if NET6_0
16
- public string Cluster { get ; set ; } = default ! ;
17
- #else
18
- #pragma warning disable SA1206
19
- public required string Cluster { get ; set ; }
20
- #pragma warning restore SA1206
21
- #endif
13
+ [ System . Text . Json . Serialization . JsonIgnore ( Condition = System . Text . Json . Serialization . JsonIgnoreCondition . WhenWritingNull ) ]
14
+ public string ? Cluster { get ; set ; }
22
15
23
16
/// <summary>
24
17
/// Tags required on servers hosting this stream
Original file line number Diff line number Diff line change
1
+ using System . Buffers ;
2
+ using System . Text ;
3
+ using NATS . Client . JetStream . Internal ;
4
+ using NATS . Client . JetStream . Models ;
5
+
6
+ namespace NATS . Client . JetStream . Tests ;
7
+
8
+ public class ParseJsonTests
9
+ {
10
+ [ Fact ]
11
+ public void Placement_properties_should_be_optional ( )
12
+ {
13
+ // This is necessary because when a KV bucket created using nats client, the placement is not set
14
+ // and the server will return an empty object for placement.
15
+ var serializer = NatsJSJsonSerializer < Placement > . Default ;
16
+
17
+ var bw = new NatsBufferWriter < byte > ( ) ;
18
+ serializer . Serialize ( bw , new Placement ( ) ) ;
19
+
20
+ var json = Encoding . UTF8 . GetString ( bw . WrittenSpan ) ;
21
+ Assert . Equal ( "{}" , json ) ;
22
+
23
+ var result = serializer . Deserialize ( new ReadOnlySequence < byte > ( bw . WrittenMemory ) ) ;
24
+ Assert . NotNull ( result ) ;
25
+ Assert . Null ( result . Cluster ) ;
26
+ Assert . Null ( result . Tags ) ;
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments