About DTO's, POCO's and JSON

I’m trying to build my services like I understand the preferred way using POCO’s etc.
I now have a simple POCO and a service to retrieve an object from the database and transfer it to the POCO:

PersoonDTO.cs

    public class PersoonDTO
{
    public int OID;
 
    public string Volledigenaam;
    public string Url;
    public string Email;
    public string Telefoon;
    public DateTime GeboorteDatum;
    public string Tussenvoegsel;
    public string Voornaam;
    public string Achternaam;
}

[Authenticate]
[Route("/Persoon/Id/{Oid}")]
public class PersoonByKey : IReturn<PersoonByKeyResponse>
{
    public int OID { get; set; }
}

public class PersoonByKeyResponse
{
    public ResponseStatus ResponseStatus { get; set; }
    public PersoonDTO Result { get; set; }
}

MyService.cs

        public object Any(PersoonByKey request)
    {
        var persoon = XafGlobal.securedObjectSpace.GetObjectByKey<Persoon>(request.OID);
        if (persoon != null)
        {
            var result = persoon.ConvertTo<PersoonDTO>();
            var back = new PersoonByKeyResponse() {Result = result};
            back.Result.OID = request.OID;
            return back;
        }
        else
        {
            return new PersoonByKeyResponse() { Result = new PersoonDTO() { OID = 0 } };
        }
    }

Everything works Ok, however when I search using for example “http://127.0.0.1:8080/Persoon/Id/2” I can see that the correct record is retrieved from the database, the PersoonDTO gets correctly filled (except for the key OID) but the response on the screen is
just “Result”. When adding “?format=json” I get {“Result”:{}} . However when I use “?format=xml” I get

<–PersoonByKeyResponse xmlns:i=“http://www.w3.org/2001/XMLSchema-instance” xmlns=“http://schemas.datacontract.org/2004/07/TimService.ServiceModel”>
<–ResponseStatus xmlns:d2p1=“http://schemas.servicestack.net/types” i:nil=“true”/>
<–Result>
<–Achternaam>Meer<–/Achternaam>
<–Email i:nil=“true”/>
<–GeboorteDatum>0001-01-01T00:00:00<–/GeboorteDatum>
<–OID>2<–/OID>
<–Telefoon i:nil=“true”/>
<–Tussenvoegsel>van der<–/Tussenvoegsel>
<–Url i:nil=“true”/>
<–Volledigenaam>Joel van der Meer<–/Volledigenaam>
<–Voornaam>Joel<–/Voornaam>
<–/Result>
<–/PersoonByKeyResponse>

(I added the ‘–’ to be able to show the XML) So the data gets transferred.
So I probably missed something about how to get from POCO to JSON in the response (I expected a JSON representation of the PersoonDTO on the screen).
Where did I go wrong?

regards

By default only public properties are serialized not public fields.

You are fast :smile:
Anyway : adding { get; set; } did the trick, my JSON is now as expected.

thanks