开发者

Jackson Jaxb Json with Apache CXf

开发者 https://www.devze.com 2023-04-04 15:47 出处:网络
I am using Jackson Jaxb JSON in my REST project with Apache CXF JacksonJaxb version . 1.7.0 Apache CXF 2.3.1

I am using Jackson Jaxb JSON in my REST project with Apache CXF

JacksonJaxb version . 1.7.0 Apache CXF 2.3.1

I am using following code to return from my method.

    @GET
    @Consumes({ "application/json", "application/xml", "text/xml" })
    @Path("/job/autosuggest")
    @Override
    public Response getSuggestions(String searchField, Integer resPerPage, String typeCont)
    {   
        List<String> respo = new ArrayList<String>();
        respo.add("Atish");
        respo.add("Narlawar");
        respo.add("India");

        return Response.ok(respo).build();
}

Now issue is coming when I compile and run the code on jetty, I get stuck with

DEBUG o.s.b.f.s.DefaultListableBeanFactory [] Finished creating instance of bean 'org.apache.cxf.phase.PhaseManager'
org.codehaus.jackson.map.JsonMappingException: Incompatible types: declared root type ([simple type, class javax.ws.rs.core.Response]) vs java.util.ArrayList

This is not particular to array or wrapper, but any object If I pass rather than String in Response.ok(object) fails to parse.

My configuration is

  <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
        <entry key="http://services.institute.com" value=""/>
        <entry key="http://cxf.apache.org/bindings/xformat" value="cxf"/>
    </util:map>

    <bean id="jsonInputFactory" class="org.codehaus.jettison.mapped.MappedXMLInputFactory">
        <constructor-arg ref="jsonNamespaceMap"/>
    </bean>

    <bean id="jsonOutputFactory" class="org.codehaus.jettison.mapped.MappedXMLOutputFactory">
        <constructor-arg ref="jsonNamespaceMap"/>
    </bean>

    <bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider"/>

    <jaxrs:server id="jobsearch" address="/">
        <jaxrs:serviceBeans>
            <ref bean="jobSearchService" />
        </jaxrs:serviceBeans>
        <jaxrs:extensionMappings>
            <entry key="text" value="text/xml"/>
            <entry key="xml" value="application/xml"/>
            <entry key="json" value="application/json"/>
        </jaxrs:extensionMappings>
        <jaxrs:languageMappings/>
        <jaxrs:properties>
            <entry key="javax.xml.stream.XMLInputFactory">
                &开发者_如何学Pythonlt;ref bean="jsonInputFactory"/>
            </entry>
            <entry key="javax.xml.stream.XMLOutputFactory">
                <ref bean="jsonOutputFactory"/>
            </entry>
        </jaxrs:properties>
        <jaxrs:providers>         
            <ref bean="jsonProvider"/>     
        </jaxrs:providers> 
    </jaxrs:server>

</beans>

I am not sure how to proceed on this issue. I already lost 1/2 day to get some workaround. Any help will be appreciated.

Thanks in advance !


At last I got the answer.

The issue is with the version itself. JacksonJaxb has reported bug in 1.7.0.

I updated the version to higher...in my case it is 1.8.5 and it got fixed.

Hope this helps.

Thanks Atish

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号