上下文 当我不导入这个库(org.apache.camel - camel-jaxb)时,代码通常执行从 json 到 pojo、pojo 到 xml 和 xml 到 pojo 的转换,但我想使用 javax 注释作为命名空间和xsd
包含 json 文件 存储库链接 github的示例存储库
图片:库骆驼 json 到 pojo - pojo 到 xml - xml 到 pojo
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jaxb</artifactId>
<version>${camel.version}</version>
</dependency>
from("file:file/json").to("direct:my-activemq-xml-queue");
from("direct:my-activemq-xml-queue").unmarshal().json(JsonLibrary.Jackson, CurrencyExchange.class)
.to("bean-validator://x?group=javax.validation.groups.Default")
.log("${body} ::::::::::::::::pojo:::::::::::::::").marshal().jacksonxml(CurrencyExchange.class)
.log("${body} :::::::::::::::::::::xml:::::::::::::::::").to("direct:my-activemq-xml-json-queue");
// converto xml to pojo
from("direct:my-activemq-xml-json-queue").unmarshal().jacksonxml(CurrencyExchange.class)
.to("log:received-message-from-active-mq");
正常转换
当我移动文件时,它工作正常,但它没有给我带来命名空间和 xsd,但它工作正常
2021-03-31 11:58:45.031 INFO 33552 --- [ile://file/json] route2 : CurrencyExchange [id=1002, from=user@gmail.com, to=DRAFT, conversionMultiple=10, bool=true, table=table [key=userg@mail.com, value=cc]] ::::::pojo::::
2021-03-31 11:58:45.093 INFO 33552 --- [ile://file/json] route2 : <CurrencyExchange><id>1002</id><from>user@gmail.com</from><to>DRAFT</to><conversionMultiple>10</conversionMultiple><bool>true</bool><table><key>userg@mail.com</key><value>cc</value></table></CurrencyExchange> :::xml:
2021-03-31 11:58:45.160 INFO 33552 --- [ile://file/json] received-message-from-active-mq : Exchange[ExchangePattern: InOnly, BodyType: com.cam.camelmicroservicesb.routes.dto.response.CurrencyExchange, Body: CurrencyExchange [id=1002, from=user@gmail.com, to=DRAFT, conversionMultiple=10, bool=true, table=table [key=userg@mail.com, value=cc]]]
错误 但是当我导入这个库时,所有的转换都是在 xml 中生成的
2021-03-31 11:30:51.012[0;39m [32m INFO[0;39m [35m34556[0;39m [2m---[0;39m [2m[ile://file/json][0;39m [36mroute2 [0;39m [2m:[0;39m <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:currencyExchange xmlns:NS2="http://www.test.com/testml" xmlns:ns2="http://www.test.com/testxml">
<ns2:id>1002</ns2:id>
<ns2:From>user@gmail.com</ns2:From>
<ns2:to>DRAFT</ns2:to>
<ns2:ConversionMultiple>10</ns2:ConversionMultiple>
<ns2:bool>true</ns2:bool>
<ns2:table>
<keyRequest>userg@mail.com</keyRequest>
<valuePcRequest>cc</valuePcRequest>
</ns2:table>
</ns2:currencyExchange>
::::::::::::::::pojo:::::::::::::::
[2m2021-03-31 11:30:51.061[0;39m [32m INFO[0;39m [35m34556[0;39m [2m---[0;39m [2m[ile://file/json][0;39m [36mroute2 [0;39m [2m:[0;39m <CurrencyExchange><id>1002</id><from>user@gmail.com</from><to>DRAFT</to><conversionMultiple>10</conversionMultiple><bool>true</bool><table><key>userg@mail.com</key><value>cc</value></table></CurrencyExchange> :::::::::::::::::::::xml:::::::::::::::::
[2m2021-03-31 11:30:51.114[0;39m [32m INFO[0;39m [35m34556[0;39m [2m---[0;39m [2m[ile://file/json][0;39m [36mreceived-message-from-active-mq [0;39m [2m:[0;39m Exchange[ExchangePattern: InOnly, BodyType: com.cam.camelmicroservicesb.routes.dto.response.CurrencyExchange, Body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:currencyExchange xmlns:NS2="http://www.test.com/testml" xmlns:ns2="http://www.test.com/testxml">
<ns2:id>1002</ns2:id>
<ns2:From>user@gmail.com</ns2:From>
<ns2:to>DRAFT</ns2:to>
<ns2:ConversionMultiple>10</ns2:ConversionMultiple>
<ns2:bool>true</ns2:bool>
<ns2:table>
<keyRequest>userg@mail.com</keyRequest>
<valuePcRequest>cc</valuePcRequest>
</ns2:table>
</ns2:currencyExchange>
]