-
Notifications
You must be signed in to change notification settings - Fork 2
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
JsonProperty equivalent? #7
Comments
It might be possible but I'm not sure how. I think it may be possible however to configure a serializer at startup to have a special handler. |
Thanks for the reply. The incoming json is not under my control, so standard naming that doesn't require the attributes is a non-starter :-( I looked into custom resolvers, which you can now (kind of) do in System.Text.Json as of .Net 7, but it seems they didn't got as far as allowing you to change the property names, which seems like a bit of an oversight. I'm thinking the cleanest option, for my end user at least, would be to supply json library specific abstractions for the model etc. |
So let me get this straight. Things that are easy:
Things that are hard:
Can you simply have a class that maps exactly and then just remap to the signature you need? |
I do own the model/dto, but its for a 3rd party api. I guess one solution would be to split the model into its own package and have a specific version for each of the supported Json libraries. |
Yeah I get it. As you can see much like having different implementations for System.Data by having other libs, this is the kind of approach I took with this project. I think I see where you're going. You're trying to open the door to allow for the consumer of your DTOs to use whatever lib they want without incurring the cost of importing all the libs. It may be possible to have an attribute provided by Open.Serialization.Json and then possibly use that as a signal/marker for the subsequent implementations to indicate what the token (name) should actually look like. It's not a trivial thing. :( Other options include: That approach sadly would not allow for simply switching a project's DI config from one to the other easily without actually importing that version. I dunno, might be fun to try it that way. |
Hello, is there any equivalent way to specify property name mappings in an agnostic manner rather than using the JsonProperty/JsonPropertyName attributes?
The text was updated successfully, but these errors were encountered: