Reputation: 429
I have created a .net Web Api project. I already have an existing Logic and Data layer and want to expose some of the data using Web Api. Everything works fine when the content-type returned is XML - all relevant records and all fields are returned correctly. However if I change the content-type to JSON - all relevant records are returned BUT only with the ID.
I have verified this using Fiddler and different browsers.
I could create a dumby class and hydrate it but that is a pain and a lot of work. Any ideas of what is going on?
PS The classes being returned have fields that only include simple types (99% sure).
Upvotes: 0
Views: 150
Reputation: 429
@Will that was it!
I have to go back and add "[DataContract]" to my classes and "[DataMember]" to the members and the data then comes through.
http://msdn.microsoft.com/en-us/library/ms733127.aspx
namespace MyTypes
{
[DataContract]
public class PurchaseOrder
{
private int poId_value;
// Apply the DataMemberAttribute to the property.
[DataMember]
public int PurchaseOrderId
{
get { return poId_value; }
set { poId_value = value; }
}
}
}
Upvotes: 1