New Posts New Posts RSS Feed: OData and JSON property names
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

OData and JSON property names

 Post Reply Post Reply
Author
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Topic: OData and JSON property names
    Posted: 21-May-2012 at 12:50pm
Hi Chris,
 
Most likely, the serializer being used does not support these attributes.
The WCF serializer supports it and should take care of the problem if used.
As per http://forums.asp.net/t/1619811.aspx/1, to use the WCF serializer you'll need to write a new ActionResult-derived type which calls into the WCF serializer. More details in the link provided.
 
Regards.


Edited by sbelini - 05-Jan-2014 at 5:49am
Back to Top
cseils View Drop Down
Newbie
Newbie
Avatar

Joined: 29-Mar-2011
Location: Australia
Posts: 10
Post Options Post Options   Quote cseils Quote  Post ReplyReply Direct Link To This Post Posted: 16-May-2012 at 5:21pm
Hi,

I have a code first Devforce BOS which has OData set up.  I am accessing the data from an iOS device in the JSON format which works fine.
However I want the property names in the JSON to be slightly different from the property names I have written in .NET.
I read that I can add an attribute to each property and the output with reflect the name configured.  See the following code:

[ProvideEntityAspect]
[IgnoreProperties(@"EntityAspect", @"AAAA_EntityAspectForSerialization")]
[DataServiceKey(@"Id")]
public class ProductCategory
{
    DataMember(Name="id")]
    public Guid Id { get; set; }

    [Required, MaxLength(20)]
    [DataMember(Name = "code")]
    public string Code { get; set; }

    [MaxLength(50)]
    [DataMember(Name = "name")]
    public string Name { get; set; }

    [Required]
    [DataMember(Name = "trackUnitsInStock")]
    public bool TrackUnitsInStock { get; set; }
}

However, even with these attributes configured, the JSON is:

{"d" : ["Id": "d4ea92f5-9008-4e8f-b695-11967d87afd6", "Code": "01", "Name": "Test", "TrackUnitsInStock": true]}

The property names are still the capitalized .net properties.
Is there an attribute that DevForce will use so I can change the names of the properties in the JSON or AtomPub? 
I really don't want to have to go through all my code and rename all the properties to match the iOS core data equivalent.
I know I have to do it with .net attributes anyway, but I would like the underlying database to have proper capitalized field names.

Thanks in advanced.
Chris
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down