Ok, you mean JSON*P*Request and JSON*P*Response, or?
JSON-P is a little different from normal JSON, it requires to be wrapped in
a callback function. Your response should look like this:
callback({"getRolesResponse":{"return":["Executive","Manager","SuperAdmin"]}}
);
The call to the callback function is required to make cross domain Ajax
work. GWT uses a function named 'callback' by default, but you can change
it.
You'll need to extend your server code to create the above result:
jsonpResponse = "callback(" + generatedJsonResponse + ");"
where "generatedJsonResponse" is the JSON generated by your JSON library.
You should only use JSON-P, if you want do do cross-domain Ajax. If
cross-domain is not required, use the RequestBuilder and JSONParser to do a
normal Ajax request and parse the resulting String.
Regards
Jan Ehrhardt
2010/6/14 malliseven.hills <[email protected]>
> Hi Jan,
> Thanks for quick reply..
>
> Yes .....your correct on conversion ...
>
> Here i'm explaining my problem please spend your valuable time for get out
> me from my problems.
>
> 1.) I'm using JSON Request and JSON Response with RestFull.
>
> Here my Restfull configuration is ..
>
> * <util:map id="nstojns" map-class="java.util.HashMap">
> <entry key="http://cxf.apache.org/bindings/xformat" value="cxf"/>
> <entry key="http://server.sample.com/" value=""/>
> <entry key="http://www.w3.org/2001/XMLSchema-instance"
> value="w3c"/>
> </util:map>
>
> <bean id="xmlInputFactory"
> class="org.codehaus.jettison.mapped.MappedXMLInputFactory">
> <constructor-arg>
> <ref bean="nstojns" />
> </constructor-arg>
> </bean>
>
> <bean id="xmlOutputFactory"
> class="com.sample.codehaus.jettison.mapped.MappedXMLOutputFactory">
> <constructor-arg>
> <ref bean="nstojns"/>
> </constructor-arg>
> </bean>
>
> [I have overridden MappedXMLOutputFactory.java for rectifying the some
> array issues i.e
> you can see the following link *
> http://jira.codehaus.org/browse/JETTISON-44 * what and all issues with
> Jettison MappedXMLOutputFactory.java
>
> NOTE: before overridden and after **overridden i'm getting same problems.*
> * ]
>
>
> <jaxws:endpoint id="SampleRESTFullService"
> implementor="#SampleRESTFullService" address="/sample/json" bindingUri="
> http://apache.org/cxf/binding/http">
> <jaxws:serviceFactory>
> <bean class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">
> <property name="properties">
> <map>
> <entry key="javax.xml.stream.XMLInputFactory"
> value-ref="xmlInputFactory" />
> <entry key="javax.xml.stream.XMLOutputFactory"
> value-ref="xmlOutputFactory"/>
> <entry key="Content-Type" value="application/json* *"/>
> </map>
> </property>
> <property name="wrapped" value="true"/>
> <property name="qualifyWrapperSchema" value="true" />
> </bean>
> </jaxws:serviceFactory>
> </jaxws:endpoint>*
>
> upto here all is fine i.e mapping JSON Object to POJO ..and perform my
> business logic and send repose as JSON Format to UI .
>
> 2.) but my problem started here when send response to UI ..its set the
> ****** response content type to text/xml******** but response
>
> {"getRolesResponse":{"return":["Executive","Manager","SuperAdmin"]}} so the
> response format JSON Response format.. thatsy browser showing error ..***not
> well-formed**
>
> So if i want (should be) rectify this problems ..i have to change the
> *******response content type to application/json****
>
> 3.) is there any way to change the response content type to
> application/json?.
> please help me out if have any way,and tel me what i have to do.(I tried
> through filter but its not helped me out).
>
> Thanks,
> Malli.
>
>
> On Mon, Jun 14, 2010 at 4:14 AM, Jan Ehrhardt <[email protected]
> > wrote:
>
>> There is no such method that does job.
>>
>> It's not really clear to me, why you will do this conversion or better
>> where? Do you want to convert it in the client (as part of your GWT app)? If
>> so, what are you doing with the two formats? Maybe it is not really
>> required, so could you give me some more details on this?
>>
>> Regards
>> Jan Ehrhardt
>>
>> 2010/6/14 Malli <[email protected]>
>>
>> Hi ,
>>>
>>> I'm using GWT2.0 I need converter from JSON to XML and XML to JSON..is
>>> there any pre-defined function for converting from JSON to XML and
>>> XML to JSON.If its so .....please tel me what that good function ..
>>> If we don't have any function please tel me how ..we can do ?
>>>
>>> Thanks,
>>> Malli.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Google Web Toolkit" group.
>>> To post to this group, send email to [email protected]
>>> .
>>> To unsubscribe from this group, send email to
>>> [email protected]<google-web-toolkit%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/google-web-toolkit?hl=en.
>>>
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google Web Toolkit" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<google-web-toolkit%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/google-web-toolkit?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-web-toolkit%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.