i have a console application that gets data from different API's.
The data that is received is mapped to a custom class. This class is later serialized into a json string. Once this is done I use urbanShip to push it to a mobile app.
My problem:
I only want the message property to bee seen once the push reaches the application. All others properties should be included but they need to be hidden. Other properties are needed in order for the app to get info about a specific object with a Id.
I have tried:
I tried using [JsonIgnore] and [DataMember] annotations on the properties that i want shown/hidden. This however did not work and I am wondering how can i accomlish this?
My code:
The class that I am currently serializing and pushing:
[DataContract]
public class SubscriberPush
{
[DataMember]
public string TrainId { get; set; }
public string Message { get; set; }
public string Title { get; set; }
public string From { get; set; }
public string To { get; set; }
public bool LateTrain { get; set; }
public bool Canceled { get; set; }
}
setting the data:
pushSub.TrainId = trainAnnouncement.AdvertisedTrainIdent;
pushSub.Title = "the train is late";
pushSub.LateTrain = true;
pushSub.Message = "train is " + span.Minutes + " min late";
string json = Parser.ConvertToJson<SubscriberPush>(pushSub);
UrbanAirship.Push(ee.DeviceToken, json);
serializer:
public static string ConvertToJson<T>(T obj)
{
var json = new JavaScriptSerializer().Serialize(obj);
return json.ToString();
}
JSON:
{"TrainId":"1036","Message":"train is 8 min late","Title":"the Train is late","From":null,"To":null,"LateTrain":true,"Canceled":false}