jsonwebservice-ri-0.8.0.jar and xmlType:dateTime (XMLGregorianCalendar)

111 views
Skip to first unread message

eam

unread,
Apr 23, 2013, 6:32:06 AM4/23/13
to jsonweb...@googlegroups.com
Hi,
I have already an application developed with jax-ws that exposes webservices and I'd like to add json support, but without change too much.
Following the guide, I can add json support only adding the library in web-inf/lib, new endpoints in sun-jaxws.xml and new servlet urls pattern in web.xml and all works properly except for all the fields declared dateTime in xsd and so XMLGregorianCalendar in Java Object.
Using json I'm not able to set the XMLGregorianCalendar in input(the error is cannot set hour minutes day etc) and I can't read this type in output (I see the field with the value "valid:true" instead the date value.
I'd like to find a solution without changing the previous code ( I have already many clients that consumes my webservices), someone has same issue?
Thanks in advance

jsonwebservice

unread,
Apr 25, 2013, 9:07:33 AM4/25/13
to jsonweb...@googlegroups.com
hi Eam,
    This is possible,  You can add custom adapter for XMLGregorianCalendar or any other class, and convert to your prefered json object type.

Regards
  Sundar

jsonwebservice

unread,
Apr 25, 2013, 9:13:45 AM4/25/13
to jsonweb...@googlegroups.com
Hi Eam,
     You can start from http://jsonwebservice.googlecode.com/svn/trunk/jsonwebservice/src/com/jaxws/json/serializer/JSONObjectCustomizer.java

  You may need to register your entention through META-INF service style.

Note: this is not documented yet from json webservice.

eam

unread,
May 2, 2013, 5:28:31 AM5/2/13
to jsonweb...@googlegroups.com
Hi,
thanks for your response. I have two questions about:
  1. I tried in the way you suggested, but  but I don't understand how to say to the framework to call my Customizer. The method initCustom in class JSONCodec is never called: it is called only in the constructor with WSBinding as parameter. Is there a way to use a custom Customizer without WSBinding? If not, how should I configure the framework in order to use WSBinding?
  2. In my custom Customizer can I write code only for the XMLGregorianCalendar data type or I have to map all supported data type?
Thanks in advance

jsonwebservice

unread,
May 2, 2013, 5:50:22 AM5/2/13
to jsonweb...@googlegroups.com
Hi Eam,
     Find bellow my answers.

Hi,
thanks for your response. I have two questions about:
  1. I tried in the way you suggested, but  but I don't understand how to say to the framework to call my Customizer. The method initCustom in class JSONCodec is never called: it is called only in the constructor with WSBinding as parameter. Is there a way to use a custom Customizer without WSBinding? If not, how should I configure the framework in order to use WSBinding?
     NO need to add any  WSBinding class.  just implement JSONObjectCustomizer and add it as service from META-INF so that parser can pick it up. find attached screen short for more information.
  1. In my custom Customizer can I write code only for the XMLGregorianCalendar data type or I have to map all supported data type?
   You need to add only for datatype you like to change, in your case XMLGregorianCalendar. Not nessary for all types.

 

jsonwebservice

unread,
May 2, 2013, 5:53:26 AM5/2/13
to jsonweb...@googlegroups.com



add your class full name in com.jaxws.json.serializer.JSONObjectCustomizer each class in one row. In your case one entry with your implementation class name of JSONObjectCustomizer.

jsonwebservice

unread,
May 2, 2013, 5:56:28 AM5/2/13
to jsonweb...@googlegroups.com

eam

unread,
May 7, 2013, 7:24:31 AM5/7/13
to jsonweb...@googlegroups.com
Hi, thanks for your support, now my custom implementation is called by framework but it is not documented how I have to write the code for XMLGregorianCalendar and I didn't found any example about.
So how I have to write the code for XMLGregorianCalendar custom serializer?
As far as I can see, decode and encode methods do not get called, even if the class is successfully loaded. Can you please provide me an example?
Thanks a lot

jsonwebservice

unread,
May 7, 2013, 7:42:43 AM5/7/13
to jsonweb...@googlegroups.com
Hi Eam,
    This is undocumented, and only for advance users.  I can't promise when document going to be created for it.

here is the untested XMLGregorianCalendar JSONObjectCustomizer.  

public class XMLGregorianCalendarSerializer implements JSONObjectCustomizer{

     public Class<? extends Object> getAcceptClass(){
return XMLGregorianCalendar.class; // Make sure correct package of XMLGregorianCalendar used.  this class is in difrent package in old version of metro.
}
   
    /**
     * To Json
     */
    public void encode(OutputStream output,Object object){
XMLGregorianCalendar  myCal  = (XMLGregorianCalendar)object;

//output.write(myCal.getCalender().toString());// what ever you like to wring in this object value in json
// WARN don't close output stream.  json encoder goig to write the rest and close at the end
// also suggested not to flush for better performance.
}
   
    /**
     * To Json
     */
    public Object decode(Object value){
// value is string if you pass date in json as string. else java.util.Map<String,Object>  you can parse and return XMLGregorianCalendar
XMLGregorianCalendar  cal = null;/// find way to construct from factory class.

return cal;
}
   
    /**
     * Content type json model
     */
    public void metaData(StringBuilder buf){
// not intrested in meta out put. leave empty.
//If intrested you can explain iin json way, and add it in this string buffer
}

}




It might be good to add generic in interface. But unfortunatly not avaiable at now.

eam

unread,
May 20, 2013, 9:20:14 AM5/20/13
to jsonweb...@googlegroups.com
Hi,
as you suggested, I followed the instructions and I was able to load my class in framework flow.
I have still quite a few problem. Let me explain the details:
1) client request object without any xmlcalendar field: I can perform the request and I get the correct response with xmlcalemdar object correctly valorized
2) client request object with xmlcalendar field:first of all, if I invoke the JSON url wsdl, the page trace an error on object serialization anch I cannot use the form; if I perform the request
in JSON format, it works, but the flow does not contains any xmlcalendar field valorized. In the method implementation I tried almost everyting: string with json format, object, I tried to replicate
what is performed for date field.. there is no way to let it work.
Before contacting you, I made a small addiction to your code: in that case, the request-response flow was invoking encode and decode method and everything was working perfectly well;
if I follow you instruction, I notice that only encode method is called. Why?


On Tuesday, April 23, 2013 12:32:06 PM UTC+2, eam wrote:

jsonwebservice

unread,
Jun 18, 2013, 9:28:12 AM6/18/13
to jsonweb...@googlegroups.com


On Monday, May 20, 2013 3:20:14 PM UTC+2, eam wrote:
Hi,

as you suggested, I followed the instructions and I was able to load my class in framework flow.
I have still quite a few problem. Let me explain the details:
1) client request object without any xmlcalendar field: I can perform the request and I get the correct response with xmlcalemdar object correctly valorized
2) client request object with xmlcalendar field:first of all, if I invoke the JSON url wsdl, the page trace an error on object serialization anch I cannot use the form; if I perform the request
in JSON format, it works, but the flow does not contains any xmlcalendar field valorized. In the method implementation I tried almost everyting: string with json format, object, I tried to replicate
what is performed for date field.. there is no way to let it work.
Before contacting you, I made a small addiction to your code: in that case, the request-response flow was invoking encode and decode method and everything was working perfectly well;
if I follow you instruction, I notice that only encode method is called. Why?



Hi Eam,
    Is it possible to give your encoder java codes. So that I can check why decode not working.

Please note: In case of  form for testing,  if you add custom encoder you also need to write form filed for your custom fileds. Thats another service customozition you have to do, if you need test form.

Reply all
Reply to author
Forward
0 new messages