Hi,

any chances you could try to pre-instantiate your lists as part of the member declaration. If that's an option to you, please try this.

Other than this, please file a Jira issue and attach a *minimal* test case for us to replay your problem. In other words, please avoid things such as derivation etc.

Regards
Werner

On 21.06.2010 11:25, avner21J wrote:

For more details I am adding here the class which is being unmarshalled, its
mapping file and how the unmarshaller is obtained. Please let me know if you
need anything else :

1. ScopeNode.java

public class ScopeNode extends GenericNode {
        
        private List<UserNode>  users;
        private List<GroupNode>  groups;
        private List<RoleNode>  roles;
        private List<ContextNode>  contexts;
        private transient int enabVirRes;
        public List<GroupNode>  getGroups() {
                return groups;
        }
        public void setGroups(List<GroupNode>  groups1) {
                this.groups = groups1;
        }

        public List<RoleNode>  getRoles() {
                return roles;
        }

        public void setRoles(List<RoleNode>  roles1) {
                this.roles = roles1;
        }

        public List<UserNode>  getUsers() {
                return users;
        }
        public void setUsers(List<UserNode>  users1) {
                this.users = users1;
        }
        public List<ContextNode>  getContexts() {
                return contexts;
        }

        public void setContexts(List<ContextNode>  contexts1) {
                this.contexts = contexts1;
        }
        public int getEnableVirtualResource() {
                return enabVirRes;
        }
        public void setEnableVirtualResource(int enabVirRes1) {
                this.enabVirRes = enabVirRes1;
        }
****************************************
2. scopenode-mapping.xml


<mapping>

        <include href="nvpair-mapping.xml"/>
        <include href="rule-mapping.xml"/>
        <include href="genericnode-mapping.xml"/>
        <include href="rolenode-mapping.xml"/>
        <include href="groupnode-mapping.xml"/>
        <include href="usernode-mapping.xml"/>
        <include href="contextnode-mapping.xml"/>
<class name="com.cisco.epm.pdp.cache.ScopeNode"
extends="com.cisco.epm.pdp.cache.GenericNode">
        
                <map-to xml="ScopeNode"/>
                
                <field name="users" type="com.cisco.epm.pdp.cache.UserNode"
collection="arraylist">
                        <bind-xml name="users" node="element"/>
                </field>
                <field name="groups" type="com.cisco.epm.pdp.cache.GroupNode"
collection="arraylist">
                        <bind-xml name="groups" node="element"/>
                </field>
                <field name="roles" type="com.cisco.epm.pdp.cache.RoleNode"
collection="arraylist">
                        <bind-xml name="roles" node="element"/>
                </field>
                <field name="contexts" 
type="com.cisco.epm.pdp.cache.ContextNode"
collection="arraylist">
                        <bind-xml name="contexts" node="element"/>
                </field>
                <field name="enabVirRes" type="integer" transient="true"
get-method="getEnableVirtualResource" set-method="setEnableVirtualResource">
                        <bind-xml name="enabVirRes" node="element"/>
                </field>
        </class>
</mapping>

****************************************
3. Code snippet for getting unmarshaller:

XMLContext xmlContext = getXMLContext();
                Reader r = new BufferedReader(new InputStreamReader(is));
                Unmarshaller unmarshaller = xmlContext.createUnmarshaller();
                 return unmarshaller.unmarshal(r);

XMLContext getXMLContext() throws Exception{
          try {
                        xmlContext = new XMLContext();
                        Mapping mapping = new Mapping();
                        mapping.loadMapping(inputSource);
                        xmlContext.addMapping(mapping);
                } catch (MappingException e) {
                        LOGGER.logError("Mapping of xml elements to class members 
failed", e);
                        throw e;
                }
}

here the inputSource is a instance variable which is initialized with Input
Stream of the mapping file of this object.I also verified that there is no
autocomplete attribute used in my mapping files.
Also a strange thing is when I use these mapping files to be read as files
rather than as input source it is working.
But currently I am reading the mapping files as :

                InputStream mappingResource =
getClass().getClassLoader().getResourceAsStream("scopenode-mapping.xml");
                inputSource = new InputSource(mappingResource);


Martin.Bolz wrote:

Hi,

thats strange even without a mapping file such a unmarshalling scenario
works for me. Could you provide a little
bit more detail? As far as I know reflection is not involved if you use a
mapping-file (assuming you not specified the
autocomplete feature in the mapping-file). Anyway could you also check
your not using one of the static unmarshalling
methods? This is a common mistake as your mapping-file is ignored then in
unmarshalling.

Regards,

Martin

-----Ursprüngliche Nachricht-----
Von: avner21J [mailto:[email protected]]
Gesendet: Montag, 21. Juni 2010 07:20
An: [email protected]
Betreff: [castor-user] org.exolab.castor.xml.MarshalException:Unable to
instantiate java.util.List


Hi,

I am using castor (ver 1.3.1) to unmarshal an xml into a java object.
This object has member variables as collections (List).

Even though in the mapping file I used collections attribute of field tag
and has set it to arraylist, it is still throwing this exception.

After doing a bit of research on this,I found that since UnmarshalHandler
uses reflection to create object from xml, it is trying to invoke
java.util.List.newInstance() which might be the root of the problem.

The class which I am trying to unmarshal is an already existing class and
I
cannot change the type of the member variables to ArrayList from List.

Exception Trace is below:

Caused by: java.lang.InstantiationException: java.util.List() method not
found
at
org.exolab.castor.xml.UnmarshalHandler.createInstance(UnmarshalHandler.java:2584)
at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:2348)
at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1436)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
Source)

I am stuck with this. Please help me resolve this.
--
View this message in context:
http://old.nabble.com/org.exolab.castor.xml.MarshalException%3AUnable-to-instantiate-java.util.List-tp28945150p28945150.html
Sent from the Castor - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

     http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

     http://xircles.codehaus.org/manage_email






---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to