Use-case: I am working on a rest service which have 3 different API endpoint. Two of the API request is of type JSON but different Specification and the third one is XML. I want to MAP these request to internal BusinessObject. I have created an internal BusinessObject which will act as a container to keep the data from either of the 3 API requests. What design pattern should I used to transform and map my API request data to BusinessObject data?
More explanation with example:
API 1 - POST : v1/employee/{id} JSON Payload Request :
{
"name" : {
"first_name" : "MyName",
"last_name" : "MyLastName"
},
"address": {
"address_line1" : "street address",
"city" : "cityname",
"country" : "countyname"
},
"work" : {
"company" : "company name",
"designation" : "position",
"Occupation" : "",
"address_line1" : "company address",
"city" : "cityname",
"country" : "countyname"
},
"other_information" : {
"DOB": "DD/MM/YYYY",
"marital_status" : "married",
"email_id" : "email@gmail.com",
}
}
API 2 - POST : v2/employee/{id} JSON Payload Request :
{
"name" : {
"first_name" : "MyName",
"last_name" : "MyLastName",
"DOB": "DD/MM/YYYY",
"marital_status" : "married",
"email_id" : "email@gmail.com"
},
"address": {
"address_line1" : "street address",
"city" : "cityname",
"country" : "countyname"
},
"work" : {
"company" : "company name",
"designation" : "position",
"Occupation" : "",
},
"work_address": {
"address_line1" : "company address",
"city" : "cityname",
"country" : "countyname"
}
}
The two request shown above are of different Request Specification type. The placeholders are different. Example : work_address
is in API 2 but not in API 1 other_information
is squeezed inside name
in API2 whereas it's a independent placeholder in API request 1.
From here i need to build a BusinessObject which is listed below. What design pattern should I used to tranform my API request data to BusinessObject data?
BusinessObject:
@NoArgsConstructor
class APIInformationContextBO {
@Getter
@Setter
private Name name;
@Getter
@Setter
private Address address;
@Getter
@Setter
private Work work;
}
Aucun commentaire:
Enregistrer un commentaire