@@ -42,3 +42,75 @@ static int s_BasicJsonParsing(struct aws_allocator *allocator, void *ctx)
4242}
4343
4444AWS_TEST_CASE (BasicJsonParsing, s_BasicJsonParsing)
45+
46+ static int s_JsonNullParseTest(struct aws_allocator *allocator, void *ctx)
47+ {
48+ (void )ctx;
49+ Aws::Crt::ApiHandle apiHandle (allocator);
50+
51+ const Aws::Crt::String jsonValue = " {\" testStringKey\" :null,\" testIntKey\" :10,"
52+ " \" array\" :[null,\" stringArrayEntry\" ],"
53+ " \" object\" :{\" testObjectStringKey\" :null}}" ;
54+
55+ Aws::Crt::JsonObject value (jsonValue);
56+ ASSERT_TRUE (value.WasParseSuccessful ());
57+
58+ auto str = value.View ().WriteCompact (true );
59+ ASSERT_STR_EQUALS (jsonValue.c_str (), str.c_str ());
60+ str = value.View ().WriteCompact (false );
61+ ASSERT_STR_EQUALS (jsonValue.c_str (), str.c_str ());
62+
63+ return AWS_OP_SUCCESS;
64+ }
65+
66+ AWS_TEST_CASE (JsonNullParsing, s_JsonNullParseTest)
67+
68+ static int s_JsonNullNestedObjectTest(struct aws_allocator *allocator, void *ctx)
69+ {
70+ (void )ctx;
71+ Aws::Crt::ApiHandle apiHandle (allocator);
72+
73+ const Aws::Crt::String jsonValue = " {\" testStringKey\" :null,\" testIntKey\" :10,"
74+ " \" array\" :[null,\" stringArrayEntry\" ],"
75+ " \" object\" :{\" testObjectStringKey\" :null}}" ;
76+
77+ Aws::Crt::JsonObject value (jsonValue);
78+ ASSERT_TRUE (value.WasParseSuccessful ());
79+
80+ Aws::Crt::JsonObject doc;
81+ doc.WithObject (" null_members" , jsonValue);
82+
83+ const Aws::Crt::String expectedValue = " {\" null_members\" :{\" testStringKey\" :null,\" testIntKey\" :10,"
84+ " \" array\" :[null,\" stringArrayEntry\" ],"
85+ " \" object\" :{\" testObjectStringKey\" :null}}}" ;
86+ auto str = doc.View ().WriteCompact (true );
87+ ASSERT_STR_EQUALS (expectedValue.c_str (), str.c_str ());
88+ str = doc.View ().WriteCompact (false );
89+ ASSERT_STR_EQUALS (expectedValue.c_str (), str.c_str ());
90+
91+ return AWS_OP_SUCCESS;
92+ }
93+
94+ AWS_TEST_CASE (JsonNullNestedObject, s_JsonNullNestedObjectTest)
95+
96+ static int s_JsonExplicitNullTest(struct aws_allocator *allocator, void *ctx)
97+ {
98+ (void )ctx;
99+ Aws::Crt::ApiHandle apiHandle (allocator);
100+
101+ const Aws::Crt::String expectedValue = " {\" testKey\" :null}" ;
102+
103+ Aws::Crt::JsonObject doc;
104+ Aws::Crt::JsonObject nullObject;
105+ nullObject.AsNull ();
106+ doc.WithObject (" testKey" , nullObject);
107+
108+ auto str = doc.View ().WriteCompact (true );
109+ ASSERT_STR_EQUALS (expectedValue.c_str (), str.c_str ());
110+ str = doc.View ().WriteCompact (false );
111+ ASSERT_STR_EQUALS (expectedValue.c_str (), str.c_str ());
112+
113+ return AWS_OP_SUCCESS;
114+ }
115+
116+ AWS_TEST_CASE (JsonExplicitNull, s_JsonExplicitNullTest)
0 commit comments