当我简单地扩展默认记录器时,为什么 Dropwizard 反序列化找不到附加程序?

Why does Dropwizard deserialization not find an appender when I simply extend the default logger?

我有一个用于配置的 YML 文件,其中包括 dropwizard 日志记录,如下所示:

logging:
  level: WARN
  loggers:
    com.<company>.<product>: INFO
  appenders:
    - type: console
(etc)

我有一个简单的 class 来读取 YAML 文件和一个 class 比如:

public class MyConfiguration {

    private CommonLoggingFactory loggingFactory;

    public MyConfiguration() {

    }

    public MyConfiguration(CommonLoggingFactory loggingFactory) {
        this.loggingFactory = loggingFactory;
    }

    @JsonProperty("logging")
    public CommonLoggingFactory getLoggingFactory() {
        return loggingFactory;
    }

    @JsonProperty("logging")
    public void setLoggingFactory(CommonLoggingFactory loggingFactory) {
        this.loggingFactory = loggingFactory;
    }
}

我的新伐木厂 class 正在...

@JsonTypeName("logging")
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = CommonLoggingFactory.class)
public class CommonLoggingFactory extends DefaultLoggingFactory {

    //TODO Any changes
}

其中 DefaultLoggingFactory 是 io.dropwizard.logging.DefaultLoggingFactory

因此,反序列化器 (jackson) 似乎可以找到 DefaultLoggingFactory,但随后不会继续沿着链到附加程序。

Could not resolve type id 'console' as a subtype of `io.dropwizard.logging.AppenderFactory<ch.qos.logback.classic.spi.ILoggingEvent>`: known type ids = [] (for POJO property 'appenders')
 at [Source: (File); line: 80, column: 1] (through reference chain: com.<my company>.MyConfiguration["logging"]->com.<mycompany>.CommonLoggingFactory["appenders"]->java.util.ArrayList[0])

我还以为会自动捡起来呢。我通过告诉对象映射器将“控制台”映射到 ConsoleAppenderFactory.class 来尝试 之类的一些事情,但没有成功。

有什么想法吗?

出于某种原因,我不得不添加以下设置方法

private void doSetup() {
   final Map<String, Class<?>> typesByName = new HashMap<String,Class<>>();
   typesByName.put("console", ConsoleAppenderFactory.class);
   SimpleModule namedTypesModule = new SimpleModule("my-named-types-module");
   Set<Class<?>> appenderFactoryClasses = new HashSet<>();
   appenderFactoryClasses.add(ConsoleAppenderFactory.class);
   appenderFactoryClasses.add(FileAppenderFactory.class);
   //etc
   namedTypesModule.registerSubtypes(appenderFactoryClasses);
   namedTypesModule.addDeserializer(Object.class, 
     new JacksonDeserializerOfNamedTypes(typesByName, 
        JsonTypeInfo.Id.Name.getPropertyName()));
   //After doing the above the read then worked ...
   ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
   mapper.readValue(file, *ExpectedClass*.class);
   ...
}