Beispiel #1
0
 /**
  * A ChainedFactory provides a way to use custom Converters that have access to the default
  * Converters. An example of use is to wrap incoming/outgoing json in a root object and delegate
  * then the ser/de to the default Converter.
  *
  * <p>This mechanism is internally used by Genson to decorate the different Converters with
  * additional behaviour (null handling, ser/de of polymorphic types with class info, runtime type
  * based ser/de, etc).
  *
  * <p>Note that you can't use it in situations where you want to start reading/writing some
  * partial infos and want to delegate the rest to the default Converter.
  */
 public GensonBuilder withConverterFactory(ChainedFactory chainedFactory) {
   if (customFactoryChain == null) customFactoryChain = chainedFactory;
   else {
     customFactoryChain.append(chainedFactory);
   }
   return this;
 }
Beispiel #2
0
  /**
   * You should override this method if you want to add custom {@link
   * com.owlike.genson.convert.ChainedFactory ChainedFactory} or if you need to chain them
   * differently.
   *
   * @return the converter <u>factory instance that will be used to resolve <strong>ALL</strong>
   *     converters</u>.
   */
  protected Factory<Converter<?>> createConverterFactory() {
    ChainedFactory chainHead = new CircularClassReferenceConverterFactory();

    chainHead.append(new NullConverterFactory(failOnNullPrimitive));

    if (useRuntimeTypeForSerialization)
      chainHead.append(new RuntimeTypeConverter.RuntimeTypeConverterFactory());

    chainHead.append(
        new ClassMetadataConverter.ClassMetadataConverterFactory(classMetadataWithStaticType));

    if (customFactoryChain != null) chainHead.append(customFactoryChain);

    if (withBeanViewConverter)
      chainHead.append(
          new BeanViewConverter.BeanViewConverterFactory(getBeanViewDescriptorProvider()));

    ContextualFactoryDecorator ctxFactoryDecorator =
        new ContextualFactoryDecorator(
            new BasicConvertersFactory(
                getSerializersMap(),
                getDeserializersMap(),
                getFactories(),
                getBeanDescriptorProvider()));

    chainHead.append(ctxFactoryDecorator);

    return chainHead;
  }