Thank you in advance and sorry for my bad english
I am using magento api to sync data
now my problem is api accept's string and use unserialize() method to convert that string and use that data
If we use that api from php we can simply generate that string using serialize() method
but i have to call that api from java and have to manage that string my self
here is example for what is happening.
Php Code :-
$gp = array(
'website_id' => '0',
'cust_group' => '1',
'price' => '5.50'
);
And After using serialize method it generates some string like this.
serialize($gp)
//it looks like : a:3:{s:10:"website_id";s:1:"0";s:10:"cust_group";s:1:"1";s:5:"price";s:4:"5.50";}
And Then in php i can use that serialized string as part of magento api's request param
(it is not whole request it is small part of my bigger request)
Now in magento api it accepts string and try to unserialize that string using php unserialize() method
$groupPrice = unserialize($gp);
so it will again create that array structure in api and that can be used like array in php.
Now My Problem comes
i want to call that api from java for that i have write some code like this which is working fine but i want to know is there any better way exist to do same
Java Code :-
String gp = getFormetedString("0","1","5.50");
// will use this gp in my request as part of arguments
public static String getFormetedString(String website_id, String cust_group, String price) {
return "a:3:{s:10:\"website_id\";s:" + website_id.length() + ":\"" + website_id + "\";"
+ "s:10:\"cust_group\";s:" + cust_group.length() + ":\"" + cust_group + "\";"
+ "s:5:\"price\";s:" + price.length() + ":\"" + price + "\";}";
}
So it will generate string like php's serialized string in java and that will we passed as part of request param in java
i can't change behavior of api and use some better encoding technique like json or xml instead of php's serialize method
so plz suggest some technique to generate string in java that is like serialized string of php's array.