axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Jordahl <t...@macromedia.com>
Subject RE: deserialization of final fields
Date Fri, 03 May 2002 17:41:39 GMT

Narve,

I have a fix for this that ignores final fields in JavaBeans when constructing the BeanPropertyDescriptors.
 I believe this will prevent the fields from getting serialized in the first place, so Axis
will not attempt to Deserialize them.

Please try out either the latest CVS build or Mondays nightly build and let me know if this
solves your issue.

Thanks.

--
Tom Jordahl
Macromedia



-----Original Message-----
From: Narve Saetre [mailto:narve@machina.no]
Sent: Friday, May 03, 2002 12:34 PM
To: axis-dev@xml.apache.org; axis-user@xml.apache.org
Subject: deserialization of final fields



It seems the BeanDeserializer does not take into account that fields may 
be final (you get a java.lang.IllegalAccessException when you try to set 
the value). I see that several people (well, at least two) have asked 
about this in the user mailing list.

An easy fix is to add

             } catch (java.lang.IllegalAccessException ex) {
             	// Final field - Ignore


on line 113 of BeanPropertyTarget.java. (From beta-2, that is, the 
complete method is shown at the bottom).

This is probably not the best solution (one should check whether the 
field is final before one even try to set the value), and it may not 
even be suitable for all purposes, but it works for me and I'll keep the 
change locally until this issue is resolved.

Please, if anybody has better solutions post them here (or update the 
source).

Regards,


Narve


--- from BeanPropertyTarget.java ---

     public void set(Object value) throws SAXException {
         try {
             if (index < 0)
                 pd.set(object, value);
             else
                 pd.set(object, index, value);
         } catch (Exception e) {
             Class type = pd.getType();
             value = JavaUtils.convert(value, type);
             try {
                 if (index < 0)
                     pd.set(object, value);
                 else
                     pd.set(object, index, value);
             } catch (java.lang.IllegalAccessException ex) {
             	// Final field - Ignore
             } catch (Exception ex) {
                 String field= pd.getName();
                 int i = 0;
                 if (index >=0) {
                     field += "[" + index + "]";
                     i = 1;
                 }
                 if (log.isErrorEnabled()) {
                     String valueType = "null";
                     if (value != null)
                         valueType = value.getClass().getName();
                     log.error(JavaUtils.getMessage("cantConvert02",
                                                    new String[] {
                                                        valueType,
                                                        field, 
                                            		pd.getType().getName()}));
                 }
                 throw new SAXException(ex);
             }
         }
     }

Mime
View raw message