Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,
I am trying to parse the complex data types like float,date etc. So when I'm trying to parse the date or float values I am getting errrors. So I will post my source code below.

Can anybody help me in sorting this out?




Java
try{
		SoapObject soapRequestforAdding = new SoapObject(NAMESPACE, METHOD_NAME_INSERT); 
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
		envelope.setOutputSoapObject(soapRequestforAdding);
		//envelope.addMapping(namespace, name, clazz)		
		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
		
		//<element name="empno" type="xsd:int" />
		int empno =Integer.parseInt(mEmpnoText.getText().toString().trim());
		PropertyInfo empnoPropInfo=new PropertyInfo();		
		empnoPropInfo.setName("empno");  
		empnoPropInfo.setValue(empno); 
		empnoPropInfo.setType(String.class);
        soapRequestforAdding.addProperty(empnoPropInfo);
        
		//<element name="empname" nillable="true" type="xsd:string" />
		String empname=mEmpnameText.getText().toString().trim();
		PropertyInfo empnamePropInfo=new PropertyInfo();
		empnamePropInfo.setName("empname");
		empnamePropInfo.setValue(empname);
		empnamePropInfo.setType(String.class);
		soapRequestforAdding.addProperty(empnamePropInfo);
		
		//<element name="username" nillable="true" type="xsd:string" />
        String username=mUsernameText.getText().toString().trim();
        PropertyInfo usernamePropInfo=new PropertyInfo();
        usernamePropInfo.setName("username");  
        usernamePropInfo.setValue(username); 
        usernamePropInfo.setType(String.class);
        soapRequestforAdding.addProperty(usernamePropInfo);
        
		//<element name="employeeaddress" nillable="true" type="xsd:string" />
        String employeeaddress=mAddressText.getText().toString().trim();
        PropertyInfo addressPropInfo=new PropertyInfo();
        addressPropInfo.setName("employeeaddress");  
        addressPropInfo.setValue(employeeaddress); 
        addressPropInfo.setType(String.class);
        soapRequestforAdding.addProperty(addressPropInfo);
        
		//<element name="city" nillable="true" type="xsd:string" />
        String city=mCityText.getText().toString().trim();
        PropertyInfo cityPropInfo=new PropertyInfo();
        cityPropInfo.setName("city");  
        cityPropInfo.setValue(city); 
        cityPropInfo.setType(String.class);
        soapRequestforAdding.addProperty(cityPropInfo);
        
		//<element name="pincode" type="xsd:int" />
        int pincode=Integer.parseInt(mPincodeText.getText().toString().trim());
        PropertyInfo pincodePropInfo=new PropertyInfo();
        pincodePropInfo.setName("pincode");  
        pincodePropInfo.setValue(pincode); 
        pincodePropInfo.setType(String.class);
        soapRequestforAdding.addProperty(pincodePropInfo);
        
		//<element name="mobileno" type="xsd:long" />
        long mobileno=Long.parseLong(mMobilenoText.getText().toString().trim());
        PropertyInfo mobilenoPropInfo=new PropertyInfo();
        mobilenoPropInfo.setName("mobileno");  
        mobilenoPropInfo.setValue(mobileno); 
        mobilenoPropInfo.setType(String.class);
        soapRequestforAdding.addProperty(mobilenoPropInfo);
        
		//<element name="dateofbirth" nillable="true" type="xsd:date" />
      //  Date dateofbirth=dateFormater.parse(mDobText.getText().toString().trim());
        String dateofbirth=mDobText.getText().toString().trim();
        PropertyInfo dateofbirthPropInfo=new PropertyInfo();
        dateofbirthPropInfo.setName("dateofbirth");  
        dateofbirthPropInfo.setValue(dateofbirth); 
    //    dateofbirthPropInfo.setType(Date.class);
        soapRequestforAdding.addProperty(dateofbirthPropInfo);
        
		//<element name="salary" type="xsd:float" />
        float salary=Float.parseFloat(mSalaryText.getText().toString().trim());
        PropertyInfo salaryPropInfo=new PropertyInfo();
        salaryPropInfo.setName("salary");  
        salaryPropInfo.setValue(salary); 
        salaryPropInfo.setType(float.class);
        soapRequestforAdding.addProperty(salaryPropInfo);
        
		//<element name="joiningdate" nillable="true" type="xsd:date" />
        Date joiningdate=dateFormater.parse(mJoinText.getText().toString().trim());
        PropertyInfo joiningdatePropInfo=new PropertyInfo();
        joiningdatePropInfo.setName("joiningdate");  
      //  joiningdatePropInfo.setValue(joiningdate); 
        //joiningdatePropInfo.setType(String.class);
        soapRequestforAdding.addProperty(joiningdatePropInfo);
        
		//<element name="relieavingdate" nillable="true" type="xsd:date" />
        Date relieavingdate=dateFormater.parse(mRelieveText.getText().toString().trim());
        PropertyInfo relieavingdatePropInfo=new PropertyInfo();
        relieavingdatePropInfo.setName("relieavingdate");  
        relieavingdatePropInfo.setValue(relieavingdate); 
      //  relieavingdatePropInfo.setType(String.class);
        soapRequestforAdding.addProperty(relieavingdatePropInfo);
        
		//<element name="createddtm" nillable="true" type="xsd:string" />
        String createddtm=mCreatedtmText.getText().toString().trim();
        PropertyInfo createddtmPropInfo=new PropertyInfo();
        createddtmPropInfo.setName("createddtm");  
        createddtmPropInfo.setValue(createddtm); 
        createddtmPropInfo.setType(String.class);
        soapRequestforAdding.addProperty(createddtmPropInfo);
        
		//<element name="creator" nillable="true" type="xsd:string" />
        String creator=mCreatorText.getText().toString().trim();
        PropertyInfo creatorPropInfo=new PropertyInfo();
        creatorPropInfo.setName("creator");  
        creatorPropInfo.setValue(creator); 
        creatorPropInfo.setType(String.class);
        soapRequestforAdding.addProperty(creatorPropInfo);
        
		//<element name="updateddtm" nillable="true" type="xsd:string" />
        String updateddtm=mUpdatedText.getText().toString().trim();
        PropertyInfo updateddtmPropInfo=new PropertyInfo();
        updateddtmPropInfo.setName("updateddtm");  
        updateddtmPropInfo.setValue(updateddtm); 
        updateddtmPropInfo.setType(String.class);
        soapRequestforAdding.addProperty(updateddtmPropInfo);
        
		//<element name="modifier" nillable="true" type="xsd:string" />
        String modifier=mModifierText.getText().toString().trim();
        PropertyInfo modifierPropInfo=new PropertyInfo();
        modifierPropInfo.setName("modifier");  
        modifierPropInfo.setValue(modifier); 
        modifierPropInfo.setType(String.class);
        soapRequestforAdding.addProperty(modifierPropInfo);
        
		//<element name="branchno" type="xsd:int" />
        int branchno=Integer.parseInt(mBranchnoText.getText().toString().trim());
        PropertyInfo branchnoPropInfo=new PropertyInfo();
        branchnoPropInfo.setName("branchno");  
        branchnoPropInfo.setValue(branchno); 
        branchnoPropInfo.setType(String.class);
        soapRequestforAdding.addProperty(branchnoPropInfo);
        
		//<element name="gender" nillable="true" type="xsd:string" />
        String gender=mGenderText.getText().toString().trim();
        PropertyInfo genderPropInfo=new PropertyInfo();
        genderPropInfo.setName("gender");  
        genderPropInfo.setValue(gender); 
        genderPropInfo.setType(String.class);
        soapRequestforAdding.addProperty(genderPropInfo);
        
		//<element name="jobtype" nillable="true" type="xsd:string" />
        String jobtype=mJobTypeText.getText().toString().trim();
        PropertyInfo jobtypePropInfo=new PropertyInfo();
        jobtypePropInfo.setName("jobtype");  
        jobtypePropInfo.setValue(jobtype); 
        jobtypePropInfo.setType(String.class);
        soapRequestforAdding.addProperty(jobtypePropInfo);
        
		//<element name="country" nillable="true" type="xsd:string" />
        String country=mCountryText.getText().toString().trim();
        PropertyInfo countryPropInfo=new PropertyInfo();
        countryPropInfo.setName("country");  
        countryPropInfo.setValue(country); 
        countryPropInfo.setType(String.class);
        soapRequestforAdding.addProperty(countryPropInfo);
        
		//<element name="state" nillable="true" type="xsd:string" />
        String state=mStateText.getText().toString().trim();
        PropertyInfo statePropInfo=new PropertyInfo();
        statePropInfo.setName("state");  
        statePropInfo.setValue(state); 
        statePropInfo.setType(String.class);
        soapRequestforAdding.addProperty(statePropInfo);
        
		//<element name="telephoneno" type="xsd:long" />
        long telephoneno=Long.parseLong(mTelephoneText.getText().toString().trim());
        PropertyInfo telephonenoPropInfo=new PropertyInfo();
        telephonenoPropInfo.setName("telephoneno");  
        telephonenoPropInfo.setValue(telephoneno); 
        telephonenoPropInfo.setType(String.class);
        soapRequestforAdding.addProperty(telephonenoPropInfo);   


		HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);


		androidHttpTransport.call(SOAP_ACTION_INSERT, envelope);      

		SoapObject obj = (SoapObject) envelope.getResponse();			 
		
		mEnterempno.setText(obj.getPropertySafelyAsString(""));
		
	}
		catch(Exception e) {

		e.printStackTrace();
		lblResult.setText("ERROR:" + e.getClass().getName() + ": " + e.getMessage());
	}

	}
		
	}




	public Object readInstance(XmlPullParser parser, String NAMESPACE, String name,
			PropertyInfo Expected) throws IOException, XmlPullParserException {
		// TODO Auto-generated method stub
		return Float.parseFloat(parser.nextText());
	}




	public void register(SoapSerializationEnvelope envelope) {
		// TODO Auto-generated method stub
		envelope.addMapping(NAMESPACE, "METHOD_NAME_INSERT", New.class, this);
	}




	public void writeInstance(XmlSerializer writer, Object arg1)
			throws IOException {
		writer.text(arg1.toString());
		// TODO Auto-generated method stub
		
	}
}
Posted
Updated 25-Apr-12 18:53pm
v6
Comments
Manfred Rudolf Bihy 23-Apr-12 9:36am    
Added code tags, sorted out spelling, grammar and text speak.
rathurocks 25-Apr-12 1:02am    
HI,
Thanks for ur reply..
The thing is, i just want to insert the data like complex data type(date,float double values) into webservice.
If i run this code means i am getting error " java.lang.RuntimeException: Cannot serialize: Mon May 02 00:00:00 GMT+05:30 1988"
Manfred Rudolf Bihy 23-Apr-12 9:39am    
Instead of dumping all that code on us, it would have been helpfull for us if you had mentioned what the exact error was you were observing.
Please read the FAQ. It will outline how to proceed when asking a qestion.
Praveen Meghwal 26-Apr-12 0:54am    
Formatted the code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900