@@ -250,6 +250,44 @@ public void Serializes_attributes_properly()
250250 Assert . AreEqual ( expected , output . Trim ( ) ) ;
251251 }
252252
253+ [ TestMethod ]
254+ [ DeploymentItem ( @"Data\ReformatsRawJsonStringWithUnquotedKeys.json" ) ]
255+ public void Reformats_raw_json_string_with_unquoted_keys ( )
256+ {
257+ // Arrange
258+ JsonApiFormatter formatter = new JsonApiFormatter ( new PluralizationService ( ) ) ;
259+ MemoryStream stream = new MemoryStream ( ) ;
260+
261+ // Act
262+ var payload = new [ ] { new Comment { Id = 5 , CustomData = "{ unquotedKey: 5 }" } } ;
263+ formatter . WriteToStreamAsync ( typeof ( Comment ) , payload , stream , null , null ) ;
264+
265+ // Assert
266+ var minifiedExpectedJson = JsonHelpers . MinifyJson ( File . ReadAllText ( "ReformatsRawJsonStringWithUnquotedKeys.json" ) ) ;
267+ string output = System . Text . Encoding . ASCII . GetString ( stream . ToArray ( ) ) ;
268+ Trace . WriteLine ( output ) ;
269+ output . Should ( ) . Be ( minifiedExpectedJson ) ;
270+ }
271+
272+ [ TestMethod ]
273+ [ DeploymentItem ( @"Data\MalformedRawJsonString.json" ) ]
274+ public void Does_not_serialize_malformed_raw_json_string ( )
275+ {
276+ // Arrange
277+ JsonApiFormatter formatter = new JsonApiFormatter ( new PluralizationService ( ) ) ;
278+ MemoryStream stream = new MemoryStream ( ) ;
279+
280+ // Act
281+ var payload = new [ ] { new Comment { Id = 5 , CustomData = "{ x }" } } ;
282+ formatter . WriteToStreamAsync ( typeof ( Comment ) , payload , stream , null , null ) ;
283+
284+ // Assert
285+ var minifiedExpectedJson = JsonHelpers . MinifyJson ( File . ReadAllText ( "MalformedRawJsonString.json" ) ) ;
286+ string output = System . Text . Encoding . ASCII . GetString ( stream . ToArray ( ) ) ;
287+ Trace . WriteLine ( output ) ;
288+ output . Should ( ) . Be ( minifiedExpectedJson ) ;
289+ }
290+
253291 [ TestMethod ]
254292 [ DeploymentItem ( @"Data\FormatterErrorSerializationTest.json" ) ]
255293 public void Should_serialize_error ( )
0 commit comments