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:


    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;

public class PersoonByKey : IReturn<PersoonByKeyResponse>
    public int OID { get; set; }

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


        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;
            return new PersoonByKeyResponse() { Result = new PersoonDTO() { OID = 0 } };

Everything works Ok, however when I search using for example “” 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”/>
<–Email i:nil=“true”/>
<–Telefoon i:nil=“true”/>
<–Tussenvoegsel>van der<–/Tussenvoegsel>
<–Url i:nil=“true”/>
<–Volledigenaam>Joel van der Meer<–/Volledigenaam>

(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?


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.