This project has moved and is read-only. For the latest updates, please go here.


Properties aren't serialized correctly


I have class "Response" that is used as a return result for one of my functions:
Public Class Response
Private _status As String
Public Property Status() As String
        Return _status
    End Get
    Set(ByVal value As String)
        _status = value
    End Set
End Property
End Class
In webapi, userscontroller has the following function "Login" :
Public Function Login(email As String, password As String) As Response
'some code goes here
Dim failedResponse As New Response
failedResponse.Status = "failed"
return failedResponse
End Function
Now here is the part that is confusing me,the returned json is:
_status: "failed"
I thought that my response should use the public naming of the property which is "Status" not the private value "_status", Am I missing anything or is it a bug?
I have the latest version of which is till today: 4.5.8
I also have the latest version of Webapi : 4.0.2071.0,as far as I know jsonformatter uses by default in RC and later versions/RTM.
EDIT: Strange,if I reinitialize SerializerSettings of JsonFormatter it works as I want,but WHY?!!
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    RouteTable.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}",
                                   New With {.id = Http.RouteParameter.Optional})
    Dim jsonFormatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter

    'Code before last change

    'Code after changes
    Dim jsonSettings As New JsonSerializerSettings
    jsonSettings.Converters.Add(New IsoDateTimeConverter)
    jsonSettings.NullValueHandling = NullValueHandling.Ignore
    jsonFormatter.SerializerSettings = jsonSettings
    'end changes

    'Force the Web Api to return JSON to the browser by default

End Sub
Closed Aug 31, 2012 at 11:51 AM by JamesNK
I don't know. Ask the Web API team