简体   繁体   中英

Automatically marshall JSON in Camel

Apache camel seems to be quite happy marshalling JAXB annotated classes, eg:

@XmlRootElement(name = "authPlayerRequest")
public class AuthPlayerRequest {

    @XmlElement(required = true)
    protected Player player;
}

If this is on a servlet://... route then this works just fine.

However... I want JSON. This does not appear to work automatically and I cannot figure out how to get it to work.

How can I get it to work?

You need to declare the JSON handler and sometimes give it a hint to the annotated class.

<dataFormats>
    <json id="pojo" library="Jackson" unmarshalTypeName="com.co.Pojo"/>
</dataFormats>

<route id="myRouteUsingJson">
    <from uri="..." />
    <unmarshal ref="pojo" />
    <bean ref="myClassThatNeedAPojo" method="doStuffPojoAsParameter" />
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM