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

Does anyone have an example on how to map a simple string into a complex type? #161

Closed
shanerogers opened this issue Dec 5, 2018 · 3 comments

Comments

@shanerogers
Copy link

No description provided.

@shanerogers
Copy link
Author

I am trying to map a string to a complex type. A string that represents an account number. The complex type will have a a formatted acc no as provide below.

"account": {
            "id": null,
            "accountNumberFormatted": null
        },

the boundry will eventually become json as above.

@shanerogers
Copy link
Author

I have tried adding a map for string -> account complex type... nothing.

I'm I missing something? With Automapper I'd create a resolver or converter.. I am trying to see if this mapping framework will be good for our project moving forward.

Help.

@chaowlert
Copy link
Collaborator

If your source/target type can be JObject instead of string, you can use Json plugin.

Or if you have specific destination type, then you can use MapWith

TypeAdapterConfig<string, ComplexType>.NewConfig()
            .MapWith(str => JsonConvert.DeserializeObject<ComplexType>(str));

But if you would like to map string from/to generic complex type, you might need to create custom adapter. Pls see JsonAdapter as an example.

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

2 participants