Is it possible to serialize long member as string?
AachoLoya opened this issue · 3 comments
AachoLoya commented
I have c# models with ID field defined as a long. Need to serialize the data into json, but since JavaScript doesn't support 64-bit values, I need to serialize only ID field as string, but in c# model keep it as long.
public class Profile
{
public long ID;
public string name;
public long userData;
}
Anyway to mark the ID field so its serialized as string? Hoping there is an attribute that I can use.
AachoLoya commented
Does anyone know?
tomsoftware commented
May you could try to proxy your value for Json using a getter / setter
public class Test
{
[IgnoreDataMember]
public long Id { get; set; }
[DataMember(Name = "Id")]
public string IdAsString
{
get
{
return Id.ToString();
}
set
{
this.Id = long.Parse(value);
}
}
}
AachoLoya commented
I think that's the best way to go about doing this.