Hi all
I saw in archives this question appeares before (for example here
http://marc.theaimsgroup.com/?l=axis-user&m=107547213309713&w=2 )
But I could not find any answer. So I post this question again with hope to
get the hint.
Problem :
1) There is JAVA-class generated with WDSL2JAVA according to schema.
2) There is XML file wich fits to the same schema.
Task : deserialize XML to JAVA class without additional tools out of the
boundaries of AXIS-framework (Castor,JAXP etc..)
Possible solution could be like this (but this one do not work correctly):
----------------------------------------------
//For this example I use object Phone from samples/addr in standard
AXIS-distribution
//Class is generated from following schema (in
samples\addr\AddressBook.wsdl ) :
/* <xsd:complexType name="phone">
<xsd:all>
<xsd:element name="areaCode" type="xsd:int"/>
<xsd:element name="exchange" type="xsd:string"/>
<xsd:element name="number" type="xsd:string"/>
</xsd:all>
</xsd:complexType> */
//It is simple object with 3 fields
DeserializerFactory df =
BaseDeserializerFactory.createFactory(
Class.forName("org.apache.axis.encoding.ser.BeanDeserializerFactory"),
Class.forName("samples.addr.Phone"),
new QName("phone"));
org.apache.axis.encoding.Deserializer des=
(org.apache.axis.encoding.Deserializer)df.getDeserializerAs(Constants.AXIS_S
AX);
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
SAXParser parser = parserFactory.newSAXParser();
XMLReader xmlReader = parser.getXMLReader();
xmlReader.setContentHandler((ContentHandler)des);
//Following XML was created by org.apache.axis.encoding.ser.BeanSerializer
from JAVA-object Phone
//I expect that this XML will be correctly understood by BeanDeserializer
String test_xml="<?xml version=\"1.0\"
encoding=\"UTF-8\"?><phone><areaCode xsi:type=\"xsd:int\" xmlns:xsi=
\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">22</areaCode><exchange
xsi:type=\"xsd:string\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">777</exchange><number
xsi:type=\"xsd:string\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">qwertyu</number></phone>";
StringReader sr = new StringReader(test_xml);
xmlReader.parse(new InputSource(sr));
//Problem appears here :
System.out.println("des:"+((samples.addr.Phone)des.getValue()).getNumber());
//Fields in object Phone contain no values from XML.
----------------------------------------------
What is here wrong in this example?
Why deserializer do not put values from XML into JAVA-object?
Could somebody help?
WBR Slava