JAXB-StringWriter修剪字符串转换时的值,但在控制台中打印整个xml字符串

问题描述

我正在尝试将Java对象转换为XML字符串,以将字符串值传递给RabbitMQ队列。但是,当我这样做时,我使用StringWriter将XML字符串打印到控制台,也将XML写入StringWriter。下面是我的代码

//Create JAXB Context
            JAXBContext jaxbContext = JAXBContext.newInstance(BiothenticateABCWSRequest.class);
             
            //Create Marshaller
            Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
 

            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
            
            //Print XML String to Console
            StringWriter sw = new StringWriter();
             
            //Write XML to StringWriter
            jaxbMarshaller.marshal(biothenticateABCWSRequest,sw);
             
            //Verify XML Content
            xmlContent = sw.toString();
            System.out.println( xmlContent);

图片1

enter image description here

图片2

enter image description here

图片3

enter image description here

以上我遇到StringWriter的问题。当我将StringWriter sw对象转换为字符串对象xmlContent并返回它时,它会修剪返回的xml值,并且相同的字符串对象xmlContent在控制台中打印完整的值。

例如:在 Image-1 中,我有方法args中的对象具有其填充的值,并且 Image-2 中,您可以StringWriter sw对象的末尾具有修剪后的值,例如{ {1}}。 但是在 Image-3 中,它是在控制台中打印的StringWriter sw对象值。在这里,您可以看到它的完整值。

无修饰字符串对象xml控制台中的内容长度为2,32,442

带有修饰符返回的字符串对象xmlContent的长度为10,009。

我不明白为什么在...中编组后,StringWriter为什么不能从对象返回完整的xml值。 请帮助我。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)