本文介绍了杰克逊使用JSON库骆驼异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是杰克逊JSON库般地遇到了麻烦。
唯一的例外是:

  FailedToCreateRouteException:无法创建航线......因为数据格式JSON-杰克逊的无法创建。确保数据格式是有效的和相关的骆驼组成部分是在类路径present

下面是类路径的通知之初即杰克逊库是否有:

 <<<骆驼Maven的插件:2.9.0:运行(默认CLI)@ portlistener<<<---骆驼Maven的插件:2.9.0:运行(默认CLI)@ portlistener ---
CLASSPATH = [文件:/ C:/Users/andrew.b-ext/Workspace/portlistener/target/classes/, file:/C:/Users/andrew.b-ext/.m2/repository/org/$c$chaus/jackson/jackson-asl/1.9.13/jackson-core-asl-1.9.13.jar, file:/C:/Users/andrew.b-ext/.m2/repository/org/$c$chaus/jackson/jackson-mapper-asl/1.9.13/jackson-mapper-asl-1.9.13.jar, file:/C:/Users/andrew.b-ext/.m2/repository/org/$c$chaus/jackson/jackson-jaxrs/1.9.13/jackson-jaxrs-1.9.13.jar, ...略...

我的POM具有杰克逊:

 <性状>
    < camel.version> 2.12.2< /camel.version>
    < cxf.version> 2.7.8< /cxf.version>
    < activemq.version> 5.6.0< /activemq.version>
< /性状><依赖和GT;
  <&依赖性GT;
     <的groupId方式>组织codehaus.jackson< /的groupId>
     <&的artifactId GT;杰克逊核心翔升< / artifactId的>
     <&版GT; 1.9.13< /版本>
  < /依赖性>
  <&依赖性GT;
     <的groupId方式>组织codehaus.jackson< /的groupId>
     <&的artifactId GT;杰克逊映射器 - 翔升< / artifactId的>
     <&版GT; 1.9.13< /版本>
  < /依赖性>
  <&依赖性GT;
     <的groupId方式>组织codehaus.jackson< /的groupId>
     <&的artifactId GT;杰克逊JAXRS< / artifactId的>
     <&版GT; 1.9.13< /版本>
  < /依赖性>

下面是我DATAFORMAT对象的定义:

 <豆的id =jsonDataformat级=org.apache.camel.model.dataformat.JsonDataFormat>
    <属性名=unmarshalTypeVALUE =java.util.Map中的/>
    <属性名=库VALUE =禅师>< /性>
< /豆>

我试图改变jsonDataformat声明:

 <骆驼:dataFormats>
            <骆驼:JSON ID =jsonDataformat库=禅师/>
< /骆驼:dataFormats>

当我这样做,我得到一个不同的错误:

 配置问题:找不到BeanDefinitionParser的元素[dataFormats]

有人能看到我在做什么错?

谢谢,

安德鲁
整个的pom.xml

 <?XML版本=1.0编码=UTF-8&GT?;

http://maven.apache.org/maven-v4_0_0.xsd>

 < modelVersion> 4.0.0< / modelVersion>&所述;! - &所述亲本GT; <&的artifactId GT;芯LT; / artifactId的> <&的groupId GT; com.xxxx.clinical< /的groupId>
    <&版GT;&3.3.3.3.1 LT; /版本> < /母体GT; - >
<&的groupId GT; com.xxxx.clinical< /的groupId>
<&的artifactId GT; portlistener< / artifactId的>
<包装和GT;&罐子LT; /包装>
<名称>&portlistener LT; /名称>
<&版GT; 0.0.0.0.01< /版本><性状>
    < camel.version> 2.12.2< /camel.version>
    < cxf.version> 2.7.8< /cxf.version>
    < activemq.version> 5.6.0< /activemq.version>
    < jackson.version> 1.9.13< /jackson.version>
< /性状><依赖和GT;
    <&依赖性GT;
        <的groupId方式>组织codehaus.jackson< /的groupId>
        <&的artifactId GT;杰克逊核心翔升< / artifactId的>
        <&版GT; $ {jackson.version}< /版本>
    < /依赖性>
    <&依赖性GT;
        <的groupId方式>组织codehaus.jackson< /的groupId>
        <&的artifactId GT;杰克逊映射器 - 翔升< / artifactId的>
        <&版GT; $ {jackson.version}< /版本>
    < /依赖性>
    <&依赖性GT;
        <的groupId方式>组织codehaus.jackson< /的groupId>
        <&的artifactId GT;杰克逊JAXRS< / artifactId的>
        <&版GT; $ {jackson.version}< /版本>
    < /依赖性>    <&依赖性GT;
        <&的groupId GT; org.apache.cxf< /的groupId>
        <&的artifactId GT; CXF-RT-前端-JAXWS< / artifactId的>
        <&版GT; $ {cxf.version}< /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; org.apache.cxf< /的groupId>
        <&的artifactId GT; CXF-RT-运输-HTTP< / artifactId的>
        <&版GT; $ {cxf.version}< /版本>
    < /依赖性>
    <! - 如果你使用的是Jetty容器需要这种依赖 - >
    <&依赖性GT;
        <&的groupId GT; org.apache.cxf< /的groupId>
        <&的artifactId GT; CXF-RT-运输-HTTP-码头< / artifactId的>
        <&版GT; $ {cxf.version}< /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; org.apache.activemq< /的groupId>
        <&的artifactId GT;的ActiveMQ,所有与LT; / artifactId的>
        <&版GT; $ {activemq.version}< /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; org.apache.activemq< /的groupId>
        <&的artifactId GT; ActiveMQ的骆驼< / artifactId的>
        <&版GT; $ {activemq.version}< /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; org.apache.activemq< /的groupId>
        <&的artifactId GT;的ActiveMQ池< / artifactId的>
        <&版GT; $ {activemq.version}< /版本>
    < /依赖性>
    <! - 骆驼 - >
    <&依赖性GT;
        <&的groupId GT; org.apache.camel< /的groupId>
        <&的artifactId GT;骆驼核心和LT; / artifactId的>
        <&版GT; $ {camel.version}< /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; org.apache.camel< /的groupId>
        <&的artifactId GT;骆驼弹簧< / artifactId的>
        <&版GT; $ {camel.version}< /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; org.apache.xbean< /的groupId>
        <&的artifactId GT; xbean弹簧< / artifactId的>
        <&版GT; 3.15 LT; /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; org.apache.camel< /的groupId>
        <&的artifactId GT;骆驼的JMS< / artifactId的>
        <&版GT; $ {camel.version}< /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; org.apache.camel< /的groupId>
        <&的artifactId GT;骆驼HL7< / artifactId的>
        <&版GT; $ {camel.version}< /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; org.apache.camel< /的groupId>
        <&的artifactId GT;骆驼网状< / artifactId的>
        <&版GT; $ {camel.version}< /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; org.apache.camel< /的groupId>
        <&的artifactId GT;骆驼CXF< / artifactId的>
        <&版GT; $ {camel.version}< /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; org.apache.camel< /的groupId>
        <&的artifactId GT;骆驼HTTP< / artifactId的>
        <&版GT; $ {camel.version}< /版本>
    < /依赖性>
    <! - 高致病性禽流感 - >
    <&依赖性GT;
        <&的groupId GT; ca.uhn.hapi< /的groupId>
        <&的artifactId GT;高致病性禽流感基< / artifactId的>
        <&版GT; 2.1< /版本>
        <&排除GT;
            <&排斥GT;
                <&的artifactId GT; xercesImpl< / artifactId的>
                <&的groupId GT;的Xerces< /的groupId>
            < /排除>
        < /排除>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; ca.uhn.hapi< /的groupId>
        <&的artifactId GT;高致病性禽流感-结构-V25< / artifactId的>
        <&版GT; 2.1< /版本>
    < /依赖性>
    <! - 记录 - >
    <&依赖性GT;
        <&的groupId GT; org.slf4j< /的groupId>
        <&的artifactId GT; SLF4J的API< / artifactId的>
        <&版GT; 1.6.1< /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT; org.slf4j< /的groupId>
        <&的artifactId GT; SLF4J-log4j12< / artifactId的>
        <&版GT; 1.6.1< /版本>
    < /依赖性>
    <&依赖性GT;
        <&的groupId GT;的log4j< /的groupId>
        <&的artifactId GT;的log4j< / artifactId的>
        <&版GT; 1.2.16< /版本>
    < /依赖性>
< /依赖和GT;<建立>
    < defaultGoal>安装< / defaultGoal>    <&插件GT;
        <&插件GT;
            <&的groupId GT; org.apache.maven.plugins< /的groupId>
            <&的artifactId GT; Maven的编译器插件< / artifactId的>
            <&版GT; 2.3.2< /版本>
            <结构>
                <信源> 1.6 LT; /源>
                <目标> 1.6 LT; /目标与GT;
            < /结构>
        < /插件>        !< - 允许路由通过跑出'MVN骆驼:运行 - >
        <&插件GT;
            <&的groupId GT; org.apache.camel< /的groupId>
            <&的artifactId GT;骆驼Maven的插件< / artifactId的>
            <&版GT; 2.9.0< /版本>
        < /插件>
    < /插件>
< /构建>
< /项目>


解决方案

您缺少骆驼 - 杰克逊依赖性:

 <&依赖性GT;
    <&的groupId GT; org.apache.camel< /的groupId>
    <&的artifactId GT;骆驼杰克逊< / artifactId的>
    <&版GT; $ {骆驼版本}< /版本>
< /依赖性>

这拉杰克逊核心-ASL和杰克逊映射器-ASL,但不幸的是没有杰克逊JAXRS。对于后者,你仍然需要一个兼容版本的显式依赖性。

I am having trouble using the Jackson JSON library with camel.The exception is:

FailedToCreateRouteException: Failed to create route... because of Data format 'json-jackson' could not be created. Ensure the data format is valid and the associated Camel component is present on the classpath

Here is the beginning of classpath notice that the Jackson libs are there:

 <<< camel-maven-plugin:2.9.0:run (default-cli) @ portlistener <<<

--- camel-maven-plugin:2.9.0:run (default-cli) @ portlistener ---
Classpath = [file:/C:/Users/andrew.b-ext/Workspace/portlistener/target/classes/, file:/C:/Users/andrew.b-ext/.m2/repository/org/codehaus/jackson/jackson-asl/1.9.13/jackson-core-asl-1.9.13.jar, file:/C:/Users/andrew.b-ext/.m2/repository/org/codehaus/jackson/jackson-mapper-asl/1.9.13/jackson-mapper-asl-1.9.13.jar, file:/C:/Users/andrew.b-ext/.m2/repository/org/codehaus/jackson/jackson-jaxrs/1.9.13/jackson-jaxrs-1.9.13.jar, ...snip...

My pom has Jackson:

 <properties>
    <camel.version>2.12.2</camel.version>
    <cxf.version>2.7.8</cxf.version>
    <activemq.version>5.6.0</activemq.version>
</properties>

<dependencies>
  <dependency>
     <groupId>org.codehaus.jackson</groupId>
     <artifactId>jackson-core-asl</artifactId>
     <version>1.9.13</version>
  </dependency>
  <dependency>
     <groupId>org.codehaus.jackson</groupId>
     <artifactId>jackson-mapper-asl</artifactId>
     <version>1.9.13</version>
  </dependency>
  <dependency>
     <groupId>org.codehaus.jackson</groupId>
     <artifactId>jackson-jaxrs</artifactId>
     <version>1.9.13</version>
  </dependency>

Here is my definition of the Dataformat object:

<bean id="jsonDataformat" class="org.apache.camel.model.dataformat.JsonDataFormat">
    <property name="unmarshalType" value="java.util.Map" />
    <property name="library" value="Jackson"></property>
</bean>

I tried changing the jsonDataformat declaration to:

    <camel:dataFormats>
            <camel:json id="jsonDataformat" library="Jackson"/>
</camel:dataFormats>

When I do that I get a different error:

Configuration problem: Cannot locate BeanDefinitionParser for element [dataFormats]

Can anyone see what I'm doing wrong?

Thanks,

Andrewentire pom.xml

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<!--<parent> <artifactId>core</artifactId> <groupId>com.xxxx.clinical</groupId>
    <version>3.3.3.3.1</version> </parent> -->
<groupId>com.xxxx.clinical</groupId>
<artifactId>portlistener</artifactId>
<packaging>jar</packaging>
<name>portlistener</name>
<version>0.0.0.0.01</version>

<properties>
    <camel.version>2.12.2</camel.version>
    <cxf.version>2.7.8</cxf.version>
    <activemq.version>5.6.0</activemq.version>
    <jackson.version>1.9.13</jackson.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-jaxrs</artifactId>
        <version>${jackson.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <!-- This dependency is needed if you're using the Jetty container -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-all</artifactId>
        <version>${activemq.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-camel</artifactId>
        <version>${activemq.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-pool</artifactId>
        <version>${activemq.version}</version>
    </dependency>
    <!-- Camel -->
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.xbean</groupId>
        <artifactId>xbean-spring</artifactId>
        <version>3.15</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jms</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-hl7</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-netty</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-cxf</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-http</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <!-- hapi -->
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-base</artifactId>
        <version>2.1</version>
        <exclusions>
            <exclusion>
                <artifactId>xercesImpl</artifactId>
                <groupId>xerces</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v25</artifactId>
        <version>2.1</version>
    </dependency>


    <!-- logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>
</dependencies>

<build>
    <defaultGoal>install</defaultGoal>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

        <!-- allows the route to be ran via 'mvn camel:run' -->
        <plugin>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-maven-plugin</artifactId>
            <version>2.9.0</version>
        </plugin>
    </plugins>
</build>
</project>
解决方案

You are missing the camel-jackson dependency:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jackson</artifactId>
    <version>${camel-version}</version>
</dependency>

This pulls in jackson-core-asl and jackson-mapper-asl, but unfortunately not jackson-jaxrs. For the latter you still need an explicit dependency in a compatible version.

这篇关于杰克逊使用JSON库骆驼异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-27 17:50