Skip to content

Submapping or mapping with in a map #94

Description

@tmorford

I have an object:

const srcA = [{ "person": { "firstName": "John", "middleName": "Michael", "lastName": "Doe" }, "contact": { "phones": [{ "type": "cell", "number": "999-888-7777" }, { "type": "home", "number": "666-555-4444" }, { "type": "work", "number": "333-222-1111", "extension": "123" } ], "emailAddresses": [{ "type": "personal", "email": "johnnyd@gmailtest.com" }, { "type": "work", "email": "jdoe@gmailtest.com" } ], "addresses": [{ "type": "home", "lineOne": "987 Home St.", "lineTwo": "Apt G", "city": "Hometown", "state": "CO", "zip": "80027", "country": "USA" }, { "type": "work", "lineOne": "654 Work Rd.", "lineTwo": "Suite 205", "city": "Workcity", "state": "CO", "zip": "80026", "country": "USA" } ] } }, { "person": { "firstName": "Anthony", "middleName": "Scott", "lastName": "Doe", "birthDate": "1991/02/29" }, "contact": { "phones": [{ "type": "cell", "number": "666-222-4444" }], "emailAddresses": [{ "type": "personal", "email": "tonyd@gmailtest.com" }], "addresses": [{ "type": "home", "lineOne": "3456 Living St.", "city": "Hometown", "state": "CO", "zip": "80027", "country": "USA" }] } } ]

I am trying to map:
const mapA = { "[].person.firstName":"[].firstName", "[].person.middleName":"[].middleName", "[].person.lastName":"[].lastName", "[].person.birthDate":"[].birthDate", "[].contact.phones[]":"[]communication[]", "[].contact.emailAddresses[]":"[]communication[]", "[].contact.addresses[]":"[]communication[]" }

In automapper c# version I could map and then have a submap of part of the object to map also.
What I am trying to do is map "[].contact.phones[]":"[]communication[]", "[].contact.emailAddresses[]":"[]communication[]","[].contact.addresses[]":"[]communication[]"
but your system just kind of makes the phone, email and address all one node, and removes parts of the data. I would like to do somerthing like []communication[] : [{[].contact.phones[],[].contact.emailAddresses[],[].contact.addresses[] }] to give this results:
"communication": [{
"communicationMethod": "Address",
"communicationType": "Home",
"addressLineOne": "1234 Rocky Road",
"addressLineTwo": "Apt 7",
"addressCity": "Blanket",
"addressState": "CO",
"addressZip": "80029",
"addressCountry": "USA"
}, {
"communicationMethod": "EmailAddress",
"communicationType": "Personal",
"emailAddress": "robbie@email.com"
}, {
"communicationMethod": "Phone",
"communicationType": "Work",
"phoneNumber": "789-123-4444",
"phoneExtension": "978"
}

not this:
[[{
"type": "home",
"lineOne": "987 Home St.",
"lineTwo": "Apt G",
"city": "Hometown",
"state": "CO",
"zip": "80027",
"country": "USA"
}, {
"type": "work",
"lineOne": "654 Work Rd.",
"lineTwo": "Suite 205",
"city": "Workcity",
"state": "CO",
"zip": "80026",
"country": "USA"
}
], [{
"type": "home",
"lineOne": "3456 Living St.",
"city": "Hometown",
"state": "CO",
"zip": "80027",
"country": "USA"
}
]]
app.zip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions