-
Notifications
You must be signed in to change notification settings - Fork 331
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
Mapping Optional<T> to T #561
Comments
I have asked a similar question on hotchocolates slack channel the other day. I have yet to receive something usefull. If we can figure this out i will share it with the rest of the project. I think many people could take advantage of this usecase ! |
With AutoMapper you can do the following to add a type conversion, and it works great. However I was hoping to use Mapster as it is significantly faster. config
.CreateMap<Optional<T>, T>()
.ConvertUsing((s, d) => s.HasValue ? s.Value : d) |
The problem seems to be related to |
Hello, String is the same Class, what member do you want to replace with a string or this just stated as an example? |
Sorry, I misunderstood the question. I thought you were looking for a solution to the fact that the update TDistination has null When null was not transmitted TSource. |
Hello, problem in this. In this example, the conversion to a primitive. The primitive adapter does not support custom mapping processing. You @furier were right if Tsource == null && map != Projection working this section and return default(TDistination) If this not work from not primitive class please add a sample. |
Hello, probably it you want |
Hello @furier,
in this case .MapToTargetWith() not work:
I get behavior you want from primitive type, you wanted to get this for all types ?
|
I have a situation where I only want the
Source.Name
property to be mapped to theTarget.Name
property if theHasValue
flag of theSource.Name
property istrue
.I've tried to create a custom mapping using the
TypeAdapterConfig
object as shown below, but theTarget.Name
property never gets a value.Here's the code I'm using to adapt the source object to a target object:
I have so incredibly many source and target types that I dont want to explicitly create manual mapping for all the types, but in stead tell Mapster that when it encounters a property on a source class with the type of
Optional<T>
, only map it if theHasValue
flag istrue
.I am doing this a part of my HotChocolate GraphQL API, here is a link to the documentation regarding Optional properties.
The text was updated successfully, but these errors were encountered: