-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No serializer defined for type: System.DateTimeOffset #466
Comments
It isn't a scenario I have added specific code for at the current time, so: there isn't an immediate "do this and it will work" answer I can give you. Ultimately we can add a special case for it - it comes down to how many special cases are actually needed. I haven't looked at what we would need additional to store this specific type. |
Ok,thanks. ? |
Something like that, yes. I'm a little cautious of over-emphasizing any specific solution here - if that works for you: great. |
Thanks a lot |
2 years later still no solution? |
@iSeiryu that's largely because there is no "obvious" general purpose representation of |
@mgravell I have a newbie question: Would the "round-trip" format representation of
|
The real question is: what should the serialization format be. For example, for |
@jodydonetti that part of the documentation is specifically talking about the JSON interpretation, not the raw protobuf one; fundamentally, the protobuf encoding (from timestamp.proto) has no ability to round-trip offset data. The JSON interpretation chooses to parse such values, but effectively flattens them down to UTC for transmit, and again: any offset data is then lost. We could choose the same approach here (effectively by flattening DateTimeOffset down to DateTime automatically), but personally I find it non-intuitive and likely to cause more confusion and data problems than if we just say "we don't support DateTimeOffset because there isn't anywhere to store the offset; we support DateTime - use that". Or at least, if we do allow people to use DateTimeOffset, I would want it to be very clear and explicit, so people know what is happening; for example (naming is hard, note): [ProtoMember(7), SerializeAsDateTimeLosingOffset] // I did say naming was hard!
public DateTimeOffset When { get; set; } The actual name here is clearly bad, but you get the idea - meaning: IMO it is only reasonable to support this scenario if we know that the caller knows that they're losing something integral in the process. Thoughts? |
Hi @mgravell : yes, sadly I noticed that right after posting here, and that's why I immediately removed my comment, to avoid creating confusion and most importantly wasting your time. But, alas, I've failed at that, sorry 😞
Agree 100% on all the points made here.
A couple of points, based on my own personal opinions and experience. Although we don't know how people will use this, I think one of the most reasonable and common usage pattern is they will use it with an UTC timezone (so, basically, it can be represented as ticks): now one might think "well so just use a Also (whether is true or not) All of this to set the ground about people using Even when that is not the case, I would not choose the path of loosing the offset IF what you mean is keeping the "offset relative" datetime part and discarding the offset itself. IF, instead, what you mean is convert it to UTC and then discard the offset part which would be moot at that point (doing so would keep the correct instant in time), then yes, that may be a way. Another option I thought about would be to only support Since "all UTC" is quite common, one idea may be to have an option in the What do you think? |
I'll add another thing: the other option considered (using an ISO 8601 string) is equally good, in my opinion, even though it obviously waste more bytes. On the other hand it would probably never loose any information. Adding to my previous comment one possible idea to cover both ways may be to be able to specify in the Of course the new option should be used only when serializing the data, because during deserialization it should be able to handle both ways (but I don't know if trying to support this would require more space in the wire format) since data may come from a client not yet updated to the latest version of the app or anyway with a different setting. |
FWIW, the Google library seems to just use a
I think this approach would be fine. Maybe though, the one where there's support for both the ISO 8601 string (default) and the |
Hi @mgravell - has anything changed over the last few years? It looks like the official docs for .NET gRPC drop the offset and imply the time is always UTC based. https://learn.microsoft.com/en-us/aspnet/core/grpc/protobuf?view=aspnetcore-8.0#dates-and-times |
HI ,
I'm getting this exception for a class defined as follows -
public class CacheDataDictionary : ProtoBase
{
[ProtoMember(1)]
public DateTimeOffset LastSystemUpdate { get; set; }
[ProtoMember(2)]
public DateTimeOffset CacheUpdatedDate { get; set; }
[ProtoMember(3)]
public HashSet CacheKeys { get; set; }
[ProtoMember(4)]
public bool IsDeltaRefresh { get; set; }
[ProtoMember(5)]
public short MinutesToNextUpdate { get; set; }
[ProtoMember(6)]
public string UpdateMachineName { get; set; }
[ProtoMember(7)]
public string ApplicationName { get; set; }
[ProtoMember(8)]
public short ObjectVersion { get; set; }
}
where ProtoBase is defined as -
[ProtoContract]
[ProtoInclude(1, typeof(ProtoString))]
public class ProtoBase
{
Is there a problem with to serialize DateTimeOffset ?
I took the latest ( 3 alpha ) version from Nuget.
EDIT -
I saw this post-
https://stackoverflow.com/questions/7046506/can-i-serialize-arbitrary-types-with-protobuf-net/7046868#7046868
Is this still the recommended way to go ?
Thanks !
The text was updated successfully, but these errors were encountered: