neuecc/Utf8Json

Is it possible to serialize long member as string?

AachoLoya opened this issue · 3 comments

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.

Does anyone know?

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);
            }
        }
    }

I think that's the best way to go about doing this.