Serialize & Deserialize Java Object in AMF3 Format
After few days analysis we decided to send and receive all our data in AMF3 format in our latest Android project. I have attached plain NetBeans project source code to make it simple, But it should work in Android (We used Android 2.1).
You need two dependency .jar files, You can download full source code here.
http://pentharine.com/wordpress/AMF3Serializer.zip
package amf3serializer;
import com.exadel.flamingo.flex.messaging.amf.io.AMF3Deserializer;
import com.exadel.flamingo.flex.messaging.amf.io.AMF3Serializer;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author sminrana@gmail.com
*/
public class Main {
public static void main(String[] args) {
Address homeAddress = new Address();
homeAddress.address1 = "Uttara, Dhaka";
homeAddress.address2 = "Address 2";
homeAddress.city_village = "Uttara";
homeAddress.state_province = "N/A";
homeAddress.postal_code = "1230";
homeAddress.country = "BD";
//----------------------------------------------------------
// Serialize Address
//----------------------------------------------------------
ByteArrayOutputStream bao = new ByteArrayOutputStream();
try {
AMF3Serializer aamfs = new AMF3Serializer(bao);
aamfs.writeObject(homeAddress);
aamfs.flush();
} catch (Exception e) {
}
byte[] ab = bao.toByteArray();
//----------------------------------------------------------
// De serialize Address
//----------------------------------------------------------
InputStream ins = new ByteArrayInputStream(ab);
AMF3Deserializer amf = new AMF3Deserializer(ins);
Address o = null;
try {
o = (Address) amf.readObject();
System.out.println("Decoded Address Object: " + o.address1);
} catch (IOException e) {
}
}
}
No trackbacks yet.