Page MenuHomePhabricator

SerializerFactory needs to be re-designed
Closed, ResolvedPublic

Description

The SerializerFactory needs a redesign. As it is now, (some of the) serializers require specialized option objects, so the caller has to know about them in advance, which defies the purpose of the factory.

Serialization needs to be able to work recursively, so I'd suggest to use the approach we discussed for serializers during the Q/A workshop:

Have a top level serialization service that knows serialization handlers for several kinds of objects. The serialization handlers get the serialization service passed into their serialize() method along with the object to serialize, so they can use the serialization service to opaquely serialize any sub-structures:

SerializationService {

function __construct( Serializer[] );
function serialize( object $object );

}

Serializer {

function serialize( object $object, SerializationService $service );

}

Note that the name "serializer" should be reconsidered - our current serializers do not serialize, but convert to native data structures (nested arrays) which are later encoded as JSON (which is the actual serialization).

Perhaps the above could be renamed/generalized into ConverterService + Conversion, with the same basic interfaces (and perhaps even code) used to convert to and from native representation, generate HTML, etc.


Version: unspecified
Severity: normal

Details

Reference
bz49952

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 1:47 AM
bzimport set Reference to bz49952.
bzimport added a subscriber: Unknown Object (MLST).

Change 89850 had a related patch set uploaded by Daniel Kinzler:
Consolidate SerializationOptions.

https://gerrit.wikimedia.org/r/89850

Change 89850 merged by jenkins-bot:
[bug 49952] Consolidate SerializationOptions.

https://gerrit.wikimedia.org/r/89850