public void writeTo(Object obj, Class realType, Type genericType, OutputStream stream) throws IOException {
AMFMapper mapper = AMFMapperIntrospector.getAMFMapper(realType, genericType);
SerializationContext context = new SerializationContext();
Amf3Output output = new Amf3Output(context);
output.setOutputStream(stream);
output.writeObject(mapper.toAMF(obj, new AMFMappingContext()));
}
}