micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.08k stars 1.07k forks source link

Provide a way to exclude a custom JsonFactory from being used in ObjectMapperFactory #3247

Open StephenOTT opened 4 years ago

StephenOTT commented 4 years ago

MN 1.3.4

There may be multiple JsonFactory singletons in a application (such a textual JSON vs binary Json / Smile, etc etc). All of with extend from JsonFactory.

https://github.com/micronaut-projects/micronaut-core/blob/1.3.x/runtime/src/main/java/io/micronaut/jackson/ObjectMapperFactory.java#L82 uses injection of JsonFactory. Can a @Named be used on L82 such as @Named("json") so other JsonFactory singletons can exist without them being injected into the default MN ObjectMapper ?

jameskleeh commented 4 years ago

You can annotate any custom factories with @Secondary, and then for single injection the current bean will be used. You can then reference your own beans with @Named, etc..