cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Berkowitz (JIRA)" <j...@apache.org>
Subject [jira] Updated: (CXF-2720) MapType doesn't deserialize subclass instances
Date Thu, 18 Mar 2010 01:12:27 GMT

     [ https://issues.apache.org/jira/browse/CXF-2720?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Michael Berkowitz updated CXF-2720:
-----------------------------------

    Summary: MapType doesn't deserialize subclass instances  (was: MapType doesn't desrialize
subclass instances)

> MapType doesn't deserialize subclass instances
> ----------------------------------------------
>
>                 Key: CXF-2720
>                 URL: https://issues.apache.org/jira/browse/CXF-2720
>             Project: CXF
>          Issue Type: Bug
>          Components: Aegis Databinding
>    Affects Versions: 2.2.6
>         Environment: All
>            Reporter: Michael Berkowitz
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Given an object of type {{Map<TKey, TValue>}}, where, say, {{TValue}} is a base
class extended by {{TValuePrime}}, when a serialized instance contains a value of type {{TValuePrime}},
*MapType* will try to deserialize it as a {{TValue}}, ignoring the fact that it's really an
instance of {{TValuePrime}}. In many cases this will throw an exception when trying to _set_
a member that exists only in {{TValuePrime}}.   (We have observed this for the value class,
but it should be true of the key class as well).
> We have fixed this - as far as we can tell - by swiping code from *ArrayType*, which
handles these things correctly.  Here is our new version of *MapType.readObject()*:
> {{    public Object readObject(MessageReader reader, Context context) throws DatabindingException
{
>         Map<Object, Object> map = instantiateMap();
>         try {
>             while (reader.hasMoreElementReaders()) {
>                 MessageReader entryReader = reader.getNextElementReader();
>                 if (entryReader.getName().equals(getEntryName())) {
>                     Object key = null;
>                     Object value = null;
>                     while (entryReader.hasMoreElementReaders()) {
>                         MessageReader evReader = entryReader.getNextElementReader();
>                         if (evReader.getName().equals(getKeyName())) {
>                             Type kType = TypeUtil.getReadType(evReader.getXMLStreamReader(),
context.getGlobalContext(), getKeyType());
>                             key = kType.readObject(evReader, context);
>                         } else if (evReader.getName().equals(getValueName())) {
>                             Type vType = TypeUtil.getReadType(evReader.getXMLStreamReader(),
context.getGlobalContext(), getValueType());
>                             value = vType.readObject(evReader, context);
>                         } else {
>                             readToEnd(evReader);
>                         }
>                     }
>                     map.put(key, value);
>                 } else {
>                     readToEnd(entryReader);
>                 }
>             }
>             return map;
>         } catch (IllegalArgumentException e) {
>             throw new DatabindingException("Illegal argument.", e);
>         }
>     }}}
> Lacking a deep understand of the Aegis code, we did this by intuition and trial-and-error,
so it may be inefficient or even technically incorrect, but so far it works for us.  Please
get this fix, or its functional equivalent, into the codebase.
> Thanks in advance.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message