protostuff/protostuff — pull request #23 by jelgh (2014-08-26 14:14:59+00:00)
Title: Serialize Date into varint instead of fixed64, depending on RuntimeEnv.DATES_BY_VARINT

Hello,

I have a Java back-end which has DTOs with `java.util.Date`. My C# clients have `long`s in the corresponding DTOs. This de- & serialization was working when using JSON previously but stopped working when I'm now migrating to Protocol Buffers (ProtoStuff & ProtoBuf-net).

Therefore I created this environment variable that can be set with system property `protostuff.runtime.dates_by_varint`, and defaults to false (which is the current, normal, behavior).
If this environment variable is set to true, `java.util.Date` will be serialized in wire type 0 (a variable integer) instead of wire type 1 (fixed64). This allows Java POJOs to have `java.util.Date` in the DTO and be able to deserialize an incoming normal `long` into the `java.util.Date` object.

Java:

public class ClassA {
@Tag(1)
public Date date;
}

Anything else (here C#, using ProtoBuf-net):

[ProtoContract]
public class ClassA
{
[ProtoMember (1)]
public long date;
}

I'm aware this might cause extra overhead (memory-wise) when serializing a `java.util.Date`, but it is very useful.

What do you think?

Best,
Johannes