日志对象输出不正确 xml

Incorrect output with log object to xml

我需要记录 XML 消息。 我使用此代码:

    //From object to xml
public String createMarshalerDealInfoType(DealInfoType dealInfoType) {
    StringWriter contactStr = null;
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(DealInfoType.class);
        Marshaller jaxbUnmarshaller = jaxbContext.createMarshaller();
        contactStr = new StringWriter();
        jaxbUnmarshaller.marshal(dealInfoType, contactStr);
    } catch (JAXBException e) {
        log.error(e.getMessage());
    }
    return contactStr.toString();
}

测试中class:

        ResponseType ResponseType = woNspDealWS.createRequestWS(DealRequestType);
        String DealResponce = updateDealEsb.createMarshalerDealInfoType(ResponseType.getDealInfo());
        log.debug("Response: \n " + DealResponce);

问题:在日志输出中我只看到第一行响应,而不是整个消息

    18:01:42,975 DEBUG updateDeal_Test:73 - Response:  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

如何打印 XML 中的所有响应?

已解决: 解决了使用注释 @XmlRootElement 进行测试 class.

的问题

您在测试中通过的对象 class 可能为空 ResponseType.getDealInfo()

为了解决这个问题需要在测试class

中使用注解@XmlRootElement