Print Page | Close Window

OData and JSON property names

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3443
Printed Date: 13-May-2026 at 5:42am


Topic: OData and JSON property names
Posted By: cseils
Subject: OData and JSON property names
Date 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



Replies:
Posted By: sbelini
Date 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 - 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.



Print Page | Close Window