Получение обоих java-объектов как и будет генерироваться jsonproperty, пока я преобразую java-объект в JSON.
VO-класс:
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class FalconidePersonalizationVO {
private String recipient;
@JsonProperty("x-apiheader-cc")
private String xApiheaderCc;
@JsonProperty("x-apiheader")
private String xApiheader;
private List<FalconideAttachmentVO> attachments = null;
@JsonProperty("recipient_cc")
private List<String> recipientCc = null;
public String getRecipient() {
return recipient;
}
public void setRecipient(String recipient) {
this.recipient = recipient;
}
public String getXApiheaderCc() {
return xApiheaderCc;
}
public void setXApiheaderCc(String xApiheaderCc) {
this.xApiheaderCc = xApiheaderCc;
}
public String getXApiheader() {
return xApiheader;
}
public void setXApiheader(String xApiheader) {
this.xApiheader = xApiheader;
}
public List<FalconideAttachmentVO> getAttachments() {
return attachments;
}
public void setAttachments(List<FalconideAttachmentVO> attachments) {
this.attachments = attachments;
}
public List<String> getRecipientCc() {
return recipientCc;
}
public void setRecipientCc(List<String> recipientCc) {
this.recipientCc = recipientCc;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "PersonalizationVO [recipient=" + recipient + ", xApiheaderCc=" + xApiheaderCc + ", xApiheader="
+ xApiheader + ", attachments=" + attachments + ", recipientCc=" + recipientCc + "]";
}
}
Основной класс:
public class FalconideAPICall {
public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException {
try {
FalconideEmailVO falconideEmail = new FalconideEmailVO();
List<FalconidePersonalizationVO> personalizationList = new ArrayList<>();
FalconidePersonalizationVO personalization = new FalconidePersonalizationVO();
personalization.setRecipient("bharathi.senthilnathan@cognizant.com");
personalization.setXApiheader("ABC1234");
personalization.setXApiheaderCc("DEF1234");
List<String> recipientCc= new ArrayList<>();
recipientCc.add("XXXXX");
personalization.setRecipientCc(recipientCc);
personalizationList.add(personalization);
falconideEmail.setPersonalizations(personalizationList);
ObjectMapper mapperObj = new ObjectMapper();
String jsonStr = mapperObj.writerWithDefaultPrettyPrinter().writeValueAsString(falconideEmail);
System.out.println("jsonStr"+jsonStr);
}}
Вывод:
"personalizations" : [ {
"recipient" : "bharathi.senthilnathan@cognizant.com",
**"xapiheader" : "ABC1234", Which should not come
"xapiheaderCc" : "DEF1234", Which should not come **
**"x-apiheader-cc" : "DEF1234", xapiheader should come as x-apiheader-cc as I used @JSONProperty
"x-apiheader" : "ABC1234", xapiheader should come as x-apiheader-cc as I used @JSONProperty**
"recipient_cc" : [ "bharathi.senthilnathan@cognizant.com" ]
} ]
Здесь xapiheader и xapiheaderCc должны быть преобразованы в JSON.В JSON должны быть только x-apiheader-cc и x-apiheader, поскольку я использовал @JSONProperty для xapiheader и xapiheaderCc.
Не могли бы вы подтвердить, где я допустил ошибку.