1

We are in the process of migrating from servicestack 3 to 4.

I got everything converted over and rebuilt, basic testing revealed that my responses are being sent as blank objects in json but that xml was fully populated.

All my responses inherit a base response class that looks like this

[Serializable]
public class ResponseBase
{        
    public string RequestTime { get; set; }
    public string ResponseTime { get; set; }
    public DtoBase[] Data { get; set; }
    public int Total { get; set; }
}

The sample I am currently testing has the following relevant code:

[Serializable]
public class CatalogDto : DtoBase
{        

    public long CatalogId { get; set; }
    public string CatalogName { get; set; }
    public string DisplayName { get; set; }
}   

[Serializable]
public class CatalogsListResponse : ResponseBase
{
    public new CatalogDto[] Data { get; set; }
}  

[Serializable]
public class DtoBase
{
}

If I call this service with format=xml I get the expected result. If I change the format to json or jsv I get an empty object back.

XML

<?xml version="1.0" encoding="utf-8" ?>
<CatalogsListResponse>
<Alerts i:nil="true" />
<Customizations i:nil="true" />
<Data i:nil="true" />
<Error i:nil="true" />
<Errors i:nil="true" />
<Infos i:nil="true" />
<RequestTime>2014-02-03T21:20:06.2704142Z</RequestTime>
<ResponseTime>2014-02-03T21:20:06.2784216Z</ResponseTime>
<Total>4</Total>
<Warnings i:nil="true" />
 <_x003C_Data_x003E_k__BackingField>
 <d2p1:CatalogDto>
<d2p1:_x003C_CatalogId_x003E_k__BackingField>1</d2p1:_x003C_CatalogId_x003E_k__BackingField>
<d2p1:_x003C_CatalogName_x003E_k__BackingField>Classic U.S. Coins</d2p1:_x003C_CatalogName_x003E_k__BackingField>
<d2p1:_x003C_DisplayName_x003E_k__BackingField>Coin</d2p1:_x003C_DisplayName_x003E_k__BackingField>
 </d2p1:CatalogDto>
 <d2p1:CatalogDto>
<d2p1:_x003C_CatalogId_x003E_k__BackingField>7</d2p1:_x003C_CatalogId_x003E_k__BackingField>
<d2p1:_x003C_CatalogName_x003E_k__BackingField>Modern U.S. Coins</d2p1:_x003C_CatalogName_x003E_k__BackingField>
<d2p1:_x003C_DisplayName_x003E_k__BackingField>Coin</d2p1:_x003C_DisplayName_x003E_k__BackingField>
 </d2p1:CatalogDto>
 <d2p1:CatalogDto>
<d2p1:_x003C_CatalogId_x003E_k__BackingField>2</d2p1:_x003C_CatalogId_x003E_k__BackingField>
<d2p1:_x003C_CatalogName_x003E_k__BackingField>U.S. Currency</d2p1:_x003C_CatalogName_x003E_k__BackingField>
<d2p1:_x003C_DisplayName_x003E_k__BackingField>Notes</d2p1:_x003C_DisplayName_x003E_k__BackingField>
 </d2p1:CatalogDto>
 <d2p1:CatalogDto>
<d2p1:_x003C_CatalogId_x003E_k__BackingField>6</d2p1:_x003C_CatalogId_x003E_k__BackingField>
<d2p1:_x003C_CatalogName_x003E_k__BackingField>World Coins</d2p1:_x003C_CatalogName_x003E_k__BackingField>
<d2p1:_x003C_DisplayName_x003E_k__BackingField>Coin</d2p1:_x003C_DisplayName_x003E_k__BackingField>
 </d2p1:CatalogDto>
 </_x003C_Data_x003E_k__BackingField>
 </CatalogsListResponse>

JSON

{"requestTime":"2014-02-03T21:23:13.1126109Z","responseTime":"2014-02-03T21:23:13.1176150Z","error":null,"customizations":null,"data":null,"total":4,"infos":null,"errors":null,"warnings":null,"alerts":null}

JSV

{requestTime:"2014-02-03T21:24:06.9960409Z",responseTime:"2014-02-03T21:24:07.0010430Z",total:4}

I'll be happy to provide any further details needed.

Eric Morris
  • 155
  • 6

1 Answers1

2

See this earlier answer on avoiding inheritance in DTOs. If you still want to use inheritance you should change DtoBase to be an abstract class.

Note: The [Serializable] attribute has no effect in ServiceStack.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Thanks, that makes perfect sense. I am a member of the cargo cult! I tested this by refactoring one request/dto/response and it appears to have solved my problem. Out of curiosity, was the change that caused the new behavior intentional? – Eric Morris Feb 04 '14 at 16:13
  • @Emotehman there was no change, the necessary **__type** info only gets emitted when it needs to, unless the default behavior is overridden with JsConfig.IncludeTypeInfo. – mythz Feb 04 '14 at 16:35