Fixed json serialization to TextWriter. Tests added.