jeudi 4 mai 2017

How to design the model in mashup service?

I'm writting a mashup service which converts payload of user's request to another model and send it to another service.

For example, a user may send following request to my mashup service:

{
    "firstName":"Jack",
    "lastName":"Hilton",
    "email":"jh@123.com"
} 

And I would like to send such data to another service, but the service only accept data structure like:

{
    "firstName":"Jack",
    "lastName":"Hilton",
    "otherInfo":{
        "emailAddress":"jh@123.com"
    }
} 

The process could also be revert: My mashup service get the data from the service and show it to the user.

You could see there are two differences: 1. the field name is from 'email' to 'emailAddress'. 2. 'emailAddress' is a field of 'otherInfo'. My requirement is I don't want to send "email":"jh@123.com" to the other service and don't want to show "otherInfo":{"emailAddress":"jh@123.com"} to the user.

My question is what is the best practice to design such models in my mashup service? Both payload structures have same fields 'firstName' and 'lastName' but they have different structures for email. I don't want to define two models which totally has no relationship and convert them to each other. But I don't know how to use 'base class' or 'interface' to achieve such data structure.

Aucun commentaire:

Enregistrer un commentaire