The RegistryStrategy object is used to intercept the serialization process and delegate to custom converters. The custom converters are resolved from a Registry object, which is provided to the constructor. If there is no binding for a particular object then serialization is delegated to an internal strategy. All converters resolved by this are instantiated once and cached internally for performance.

By default the TreeStrategy is used to perform the normal serialization process should there be no class binding specifying a converter to use. However, any implementation can be used, including the CycleStrategy, which handles cycles in the object graph. To specify the internal strategy to use it can be provided in the constructor.

Inheritance: Strategy
示例#1
0
    //public Item GetExtendedItem() {
    //   return extendedItem;
    //}
 public void TestCombinedStrategy() {
    Registry registry = new Registry();
    AnnotationStrategy annotationStrategy = new AnnotationStrategy();
    RegistryStrategy registryStrategy = new RegistryStrategy(registry, annotationStrategy);
    Persister persister = new Persister(registryStrategy);
    CombinationExample example = new CombinationExample(1, 2, 3);
    StringWriter writer = new StringWriter();
    registry.bind(Item.class, RegistryItemConverter.class);
    //public List<Pet> GetPets() {
    //   return list;
    //}
 public void TestCycle() {
    Registry registry = new Registry();
    CycleStrategy inner = new CycleStrategy();
    RegistryStrategy strategy = new RegistryStrategy(registry, inner);
    Persister persister = new Persister(strategy);
    PetBucket bucket = new PetBucket();
    StringWriter writer = new StringWriter();
    registry.bind(Cat.class, CatConverter.class);
示例#3
0
        public void TestConverter()
        {
            Registry     registry    = new Registry();
            Strategy     interceptor = new RegistryStrategy(registry);
            Persister    persister   = new Persister(interceptor);
            StringWriter writer      = new StringWriter();
            PetShop      shop        = new PetShop();

            registry.bind(Dog.class, DogConverter.class)