The output string of the BinarySerializer seems too long. It does not change even if I shorten the property names of the class to single character length.
Here is the class file:
using System;
namespace Models.Accounts
{
/// <summary>
/// PasswordResetRequest class
/// model of a password reset request
/// </summary>
[Serializable]
public class PRR
{
/// <summary>
/// request id
/// </summary>
public string I { get; set; }
/// <summary>
/// time request received
/// </summary>
public DateTime T { get; set; }
/// <summary>
/// application to which the password belongs
/// </summary>
public string A { get; set; }
/// <summary>
/// username whose password needs to be reset
/// </summary>
public string U { get; set; }
/// <summary>
/// token (guid)
/// </summary>
public Guid G { get; set; }
/// <summary>
/// token used
/// </summary>
public bool D { get; set; }
/// <summary>
/// client ip
/// </summary>
public string C { get; set; }
}
}
and I'm using this SO link for serialization. When I use the serializer as
PRR request = new PRR();
request.U = "someusername";
request.G = Guid.NewGuid();
string searlizedRequest = SingletonCommon.Instance.SerializeObject(request);
I get a very long value for searlizedRequest like AAEAAAD/////AQAAAAAAAAAMAgAAAEFMSVQuTW9kZWxzLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAF0xJVC5Nb2RlbHMuQWNjb3VudHMuUFJSBwAAABI8ST5rX19CYWNraW5nRmllbGQSPFQ+a19fQmFja2luZ0ZpZWxkEjxBPmtfX0JhY2tpbmdGaWVsZBI8VT5rX19CYWNraW5nRmllbGQSPEc+a19fQmFja2luZ0ZpZWxkEjxEPmtfX0JhY2tpbmdGaWVsZBI8Qz5rX19CYWNraW5nRmllbGQBAAEBAwABDQtTeXN0ZW0uR3VpZAECAAAACgAAAAAAAAAACgYDAAAADHNvbWV1c2VybmFtZQT8////C1N5c3RlbS5HdWlkCwAAAAJfYQJfYgJfYwJfZAJfZQJfZgJfZwJfaAJfaQJfagJfawAAAAAAAAAAAAAACAcHAgICAgICAgL20za6r7D0QbKWb7tG1cjSAAoL
Is there any formatter with shorter output I can use or anything else I can try, since this string will be part of a link sent in an email.
XmlSerializer. You can control it with attributes and files can be edited/viewed by a human (xml is easy to understand). If you need minimum size, then you have to use binary serialization:BinarySerializer, protobuf (fastests, smallest, not human viewable/editable and required using third-party library, though very well supported). If your aim is to transfer serialized object via ascii-text channel, then why not using json, designed specially?[NonSerializable]attribute for some fields, and it reduced the size by almost 40%. Not bad for right now