enum ElementType
{
None,
+ Null,
Object,
Array,
String,
break;
case ElementType.String:
throw new XmlException ("Mixed content is not allowed in this XmlDictionaryWriter");
+ case ElementType.Null:
+ throw new XmlException ("Current type is null and writing element inside null is not allowed");
case ElementType.None:
throw new XmlException ("Before writing a child element, an element needs 'type' attribute to indicate whether the element is a JSON array or a JSON object in this XmlDictionaryWriter");
}
element_kinds.Pop ();
element_kinds.Push (ElementType.String);
break;
+ case "null":
+ element_kinds.Pop ();
+ element_kinds.Push (ElementType.Null);
+ OutputString ("null");
+ break;
default:
throw new XmlException (String.Format ("Unexpected type attribute value '{0}'", attr_value));
}
else if (text == null) {
no_string_yet = false;
is_null = true;
- OutputString ("null");
+ if (element_kinds.Peek () != ElementType.Null)
+ OutputString ("null");
} else {
switch (element_kinds.Peek ()) {
case ElementType.String:
w.Close ();
Assert.AreEqual ("\"\\/my date\\/\"", ResultString);
}
+
+ [Test]
+ public void WriteNullType ()
+ {
+ w.WriteStartElement ("root");
+ w.WriteAttributeString ("type", "object");
+ w.WriteStartElement ("foo");
+ w.WriteAttributeString ("type", "null");
+ w.Close ();
+ Assert.AreEqual ("{\"foo\":null}", ResultString);
+ }
}
}