Skip to content
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

Custom BreezeJS DataTypes (in the context of NodaTime) #65

Open
juliancarrivick opened this issue Apr 24, 2022 · 0 comments
Open

Custom BreezeJS DataTypes (in the context of NodaTime) #65

juliancarrivick opened this issue Apr 24, 2022 · 0 comments

Comments

@juliancarrivick
Copy link

I have been looking at using NodaTime on my entities and am unable to get BreezeJS to treat NodaTime values as a JS Date. In the metadata the property's datatypes are the NodaTime type (e.g. NodaTime.LocalDate) which doesn't map to the BreezeJS DataType.DateTime. Side note, is this going to be an issue for the new .NET 6 DateOnly and TimeOnly data types?

Ideally, there would be some way to be able to transparently map these types to a JS Date, but there doesn't seem to be a way to do this unless I'm missing something.

I explored a few different ideas and there are a few ways I think this could be achieved, in descending order of what I think would be most preferable:

  • Some way to register a custom DataType which has custom (de)serialisation logic (e.g. from NodaTime.LocalDate to JS Date), however currently in BreezeJS DataType is an Enum which precludes any registration of custom types.
  • Be able to alias a given DataType from metadata to an already implemented DataType in JS. This might work for deserialisation, but is likely to have issues when serialising for the server to handle (e.g. server is expecting a LocalDate and recieves an full timestamp)
  • Hacking the metadata to force NodaTime types to be a DateTime. While this possibly might work for my specific use case, I would think a more flexible option is preferable
  • I managed to create wrapper properties on my JS entities which handle conversion between the raw string property (which BreezeJs falls back to) and a date, but this is repetitive and error prone. Perhaps if there is an automated way I could achieve this with the raw string property being a shadow property that would work but I feel there are better approaches
  • Create DTO versions of each entity with System.DateTime properties which will be handled by the client correctly. This seems to go against the philosophy of breeze, adding duplication and uneccessary mapping logic between the actual entities and the DTOs.

Any thoughts from someone with more experience with Breeze would be most appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant