The last step is to register the Factory to the SerializationConfig. Below are the programmatic and declarative configurations for this step.

Config config = new Config();
config.getSerializationConfig().addPortableFactory( 1, new MyPortableFactory() );
      <portable-factory factory-id="1">

Note that the id that is passed to the SerializationConfig is the same as the factoryId that the Foo class returns.