I have a web API built in .NET 4.0 and I have an issue with a simple GET request. My problem is that I want to return an object who has many properties, some strings, ints and other custom data types and in some cases some of those properties doesn't exist in the databsae so I want it to return an empy object {} and I'm just having null.
Here is some of my code
<ActionName("index")>
<HttpGet>
Public Function ObtenerAsegurado(<FromUri> rut As Integer) As Asegurado
Dim ws As New Getter2.GetterSoapClient
Dim aseg As Getter2.AseguradoDTO
aseg = ws.ObtenerAsegurado(rut)
Dim objAsegurado As Asegurado = Convertir.DTOToAsegurado(aseg)
Return objAsegurado
End Function
Public Shared Function DTOToAsegurado(asegDTO As Getter2.AseguradoDTO) As Asegurado
Dim aseg As New Asegurado
If Not asegDTO Is Nothing Then
...
aseg.cuenta = DTOToCuentas(asegDTO.Cuenta)
...
End If
Return aseg
End Function
Private Shared Function DTOToCuentas(cuentaDTO As Getter2.CuentaDTO) As Cuenta
Dim nuevacuenta As New Cuenta
If Not cuentaDTO Is Nothing AndAlso Not cuentaDTO.DescBanco Is Nothing Then
...
Else
nuevacuenta = Nothing
End If
Return nuevacuenta
End Function
As you can see, my action call to another function to make some convertion, and there i return the property of the object as nothing when there isn't present, that becomes null in the http response and I want an empty object instead {}
I also tried returning nuevacuenta = New Cuenta but that return an object with all it's properties set to nothing... Please help how can I return empty instead of null?
Objecttype can not be converted to the customCuentatype