Dear Sergey,

thank you for your fast response and your suggestion.

I am sorry, but it did not work. I've tried it before.

I have configured my JSONProvider now in that way

 <bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.JSONProvider">
        <property name="namespaceMap" ref="nstojns"/>
        <property name="ignoreNamespaces" value="true"/>
        <property name="attributesToElements" value="true"/>
        <property name="inTransformElements">
            <map>
                <entry key="FeedbackData" value="{
http://xyz.com/serviceapi}FeedbackData"/>
                <entry key="FeedbackEvent" value="{
http://xyz.com/serviceapi}FeedbackEvent"/>
            </map>
        </property>
    </bean>

and send the following JSON-Object

{"FeedbackData":{"FeedbackEvent":{"accessProfile":"Test"}}}

However, after the unmarshalling the property accessProfile is null. If I
provided the accessProfile as @accessProfile within the JSON-Object
everything is fine. It seems the property attributesToElements has no
effect.

Any other clue?

Regards,

Christian

 Am Dienstag, 12. Juli 2011 um 18:43 schrieb Sergey Beryozkin:

Hi,

On Tue, Jul 12, 2011 at 5:08 PM, Christian Hartmann
<[email protected]> wrote:

Hi there,

I am using Apache CXF 2.4.1 and I want to POST a JSON-String to my
RestFul-Service.

So I configure the following within my Spring 3.x configuration:

   <util:map id="nstojns" map-class="java.util.HashMap">
       <entry key="http://xyz.com/serviceapi"; value="serviceapi"/>
   </util:map>

   <bean id="jsonProvider"
class="org.apache.cxf.jaxrs.provider.JSONProvider">
       <property name="namespaceMap" ref="nstojns"/>
       <property name="ignoreNamespaces" value="true"/>
       <property name="inTransformElements">
           <map>
               <entry key="FeedbackData" value="{
http://xyz.com/serviceapi}FeedbackData"/>
               <entry key="FeedbackEvent" value="{
http://xyz.com/serviceapi}FeedbackEvent"/>
           </map>
       </property>
   </bean>

    <jaxrs:server id="cxfService"
address="${cxf.endpoint.shopservice.address}">
       <jaxrs:serviceFactories>
           <ref bean="feedbackFacadeFactory"/>
       </jaxrs:serviceFactories>
       <jaxrs:providers>
           <ref bean="jsonProvider"/>
       </jaxrs:providers>
    </jaxrs:server>

Now I can call my service and do a POST sending a JSON-Object like this:

{"FeedbackData":{"FeedbackEvent":{"@accessProfile":"Test"}}}

and the binding is done by JAXB based on a provided XSD without any
problems.

However I have to mention the ugly "@" for my attributes. Is there any way
to configure CXF and/or the JSONProvider not to have to use the "@" as a
marker for the attribute? If yes, how?


Try adding

<property name="attributesToElements" value="true"/>

that should do it

Cheers, Sergey

Any help will be appreciated.

Regards,

Christian




-- 
Sergey Beryozkin

http://sberyozkin.blogspot.com
Talend - http://www.talend.com

Reply via email to