@XmlElement 태그가있는 요소가 포함 된 계약 클래스가 있습니다. 예를 들어JSON에 직렬화하는 동안 Jackson이 @XmlElement를 고려하지 못함
@XmlElement(name = "balancemoney")
protected Amount balanceMoney;
나는 적절한 태그를 사용하여 XML을 생성 할 수 있습니다. 내가 사용하는 경우
그러나, 잭슨은 JSON 태그는 여전히 대신 'balancemoney'나는 @XmlElement 태그를 고려 잭슨을 어떻게 알 수 있습니까의 'balanceMoney'로 제공, 라이브러리를 제공했다.
아래 코드는이 작업을 수행하는 코드입니다. 에 따르면
//Function to display request object.
public void displayXML(Object reqResp){
try{
JAXBContext jaxbContext = JAXBContext.newInstance(reqResp.getClass());
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// output pretty printed
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
ByteArrayOutputStream bStream=new ByteArrayOutputStream();
//jaxbMarshaller.marshal(reqResp, System.out);
jaxbMarshaller.marshal(reqResp,bStream);
logger.info(bStream.toString());
}catch(JAXBException e){
logger.info(e.getMessage());
}
logger.info("*** Payload is: " + reqResp.toString());
}
//Function to display as JSON
public void displayJSON(Object reqResp) throws JsonGenerationException, JsonMappingException, IOException{
ObjectMapper mapper = new ObjectMapper();
logger.info(mapper.defaultPrettyPrintingWriter().writeValueAsString(reqResp));
}
아니, 그게 도움이되지 않는 것 같습니다. – Gsb128379