1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . IO ;
4+ using System . Text ;
5+ using Microsoft . Azure . Cosmos ;
6+ using Newtonsoft . Json ;
7+
8+ class Program
9+ {
10+ static void Main ( string [ ] args )
11+ {
12+ // Create a patch operation with a long numeric-looking string
13+ var longNumericString = "12345678901234567890" ;
14+ var patchOperation = PatchOperation . Add ( $ "/strings/{ longNumericString } ", "value" ) ;
15+
16+ Console . WriteLine ( $ "Original Path: { patchOperation . Path } ") ;
17+
18+ // Create a PatchSpec to simulate what gets serialized
19+ var patchSpec = new PatchSpec (
20+ new List < PatchOperation > { patchOperation } ,
21+ new PatchItemRequestOptions ( )
22+ ) ;
23+
24+ // Use the same serializer as the SDK
25+ var serializer = new CosmosJsonDotNetSerializer ( ) ;
26+ var converter = new PatchOperationsJsonConverter ( serializer ) ;
27+
28+ // Serialize to see what JSON is generated
29+ var jsonSerializer = new JsonSerializer ( ) ;
30+ jsonSerializer . Converters . Add ( converter ) ;
31+
32+ var stringWriter = new StringWriter ( ) ;
33+ var jsonWriter = new JsonTextWriter ( stringWriter ) ;
34+
35+ converter . WriteJson ( jsonWriter , patchSpec , jsonSerializer ) ;
36+
37+ var json = stringWriter . ToString ( ) ;
38+ Console . WriteLine ( $ "Generated JSON: { json } ") ;
39+
40+ // Test with other path formats
41+ var quotedPath = PatchOperation . Add ( $ "/strings/\" { longNumericString } \" ", "value" ) ;
42+ Console . WriteLine ( $ "Quoted Path: { quotedPath . Path } ") ;
43+
44+ var escapedPath = PatchOperation . Add ( $ "/strings/~{ longNumericString } ", "value" ) ;
45+ Console . WriteLine ( $ "Escaped Path: { escapedPath . Path } ") ;
46+ }
47+ }
0 commit comments