打印格式化的输出JAXB对象

时间:2019-05-26 11:13:21

标签: java jaxb

我有这个JAB对象,我想在填充它时将其打印为可读字符串:

@XmlRootElement(name = "payment_response")
@XmlAccessorType(XmlAccessType.FIELD)
public class PaymentResponse {

    @XmlElement(name = "transaction_type")
    public String transactionType;
    ....
}

我试图实现这一点:

      PaymentResponse response = new PaymentResponse("error", 340, "Please check input data for errors!", "has already been used!");

      JAXBContext jaxbContext = JAXBContext.newInstance(PaymentResponse.class);

      Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

      jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

      StringWriter responsesw = new StringWriter();
      jaxbMarshaller.marshal(response, responsesw);

      System.out.println(response.toString())

但是我只得到这个org.rest.models.PaymentResponse@71b6bc42 如何将多余的XML转换为可读的文本?

0 个答案:

没有答案