-
Notifications
You must be signed in to change notification settings - Fork 34
Provide external jackson object mapper #395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package io.quarkiverse.loggingjson.providers; | ||
|
|
||
| import jakarta.inject.Inject; | ||
| import jakarta.inject.Singleton; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
|
||
| @Singleton | ||
| public class ObjectMapperProvider { | ||
|
|
||
| @Inject | ||
| ObjectMapper mapper; | ||
|
|
||
| public ObjectMapper get() { | ||
| return this.mapper; | ||
| } | ||
|
|
||
| } | ||
|
Comment on lines
+8
to
+18
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt this will work well in practice as you want logging very early, even before ArC is set up. If you require ArC to be set up to set up logging, it might work but you will collect lots of messages and buffer them in memory before the setup is fully done. I think you probably need to use the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is to be able to get the object mapper provided from the project including the extension. Don't think the ServiceLoader will do... |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| package io.quarkiverse.loggingjson.providers; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.logging.Level; | ||
|
|
||
| import org.jboss.logmanager.ExtLogRecord; | ||
|
|
@@ -19,7 +18,7 @@ protected Type type() { | |
|
|
||
| @Test | ||
| void testDefaultConfig() throws Exception { | ||
| final Config.FieldConfig config = fieldConfig(Optional.empty(), Optional.empty()); | ||
| final Config.FieldConfig config = fieldConfig(null, null); | ||
|
Comment on lines
-22
to
+21
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's not a very good idea to mix changes that are not really related to the issue at hand. It makes the PR very verbose.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm aware of that but I considered these changes harmless and since there is no frequent activity in this repo decided to include them. |
||
| final ErrorMessageJsonProvider provider = new ErrorMessageJsonProvider(config); | ||
|
|
||
| final RuntimeException t = new RuntimeException("Testing errorMessage"); | ||
|
|
@@ -37,7 +36,7 @@ void testDefaultConfig() throws Exception { | |
|
|
||
| @Test | ||
| void testCustomConfig() throws Exception { | ||
| Config.FieldConfig config = fieldConfig(Optional.of("em"), Optional.of(false)); | ||
| Config.FieldConfig config = fieldConfig("em", false); | ||
| final ErrorMessageJsonProvider provider = new ErrorMessageJsonProvider(config); | ||
|
|
||
| final RuntimeException t = new RuntimeException("Testing errorMessage"); | ||
|
|
@@ -52,7 +51,7 @@ void testCustomConfig() throws Exception { | |
| Assertions.assertEquals("Testing errorMessage", em); | ||
| Assertions.assertFalse(provider.isEnabled()); | ||
|
|
||
| config = fieldConfig(Optional.of("em"), Optional.of(true)); | ||
| config = fieldConfig("em", true); | ||
| Assertions.assertTrue(new ErrorMessageJsonProvider(config).isEnabled()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,17 +69,17 @@ protected JsonNode getResultAsJsonNode(JsonProvider jsonProvider, ExtLogRecord e | |
| return mapper.readValue(getResult(jsonProvider, event), JsonNode.class); | ||
| } | ||
|
|
||
| protected Config.FieldConfig fieldConfig(Optional<String> fieldName, Optional<Boolean> enabled) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optionals should only be used as a return type. |
||
| protected Config.FieldConfig fieldConfig(String fieldName, Boolean enabled) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using proper types instead of Optional. |
||
| return new Config.FieldConfig() { | ||
|
|
||
| @Override | ||
| public Optional<String> fieldName() { | ||
| return fieldName; | ||
| return Optional.ofNullable(fieldName); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will return empty optional if input is null. |
||
| } | ||
|
|
||
| @Override | ||
| public Optional<Boolean> enabled() { | ||
| return enabled; | ||
| return Optional.ofNullable(enabled); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will return empty optional if input is null. |
||
| } | ||
| }; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you enforcing Yasson now? It doesn't look like an improvement?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The jsonb factory initialization is now moved from the processor to the recorder and it is instantiated only on demand. The dependency is added because the native build starts to break without it.
Error: Discovered unresolved type during parsing: org.eclipse.yasson.internal.JsonBindingBuilder. This error is reported at image build time because class io.quarkiverse.loggingjson.jsonb.JsonbJsonFactory is registered for linking at image build time by command line and command line.
This solution appears to be working but if there is a better / correct way to solve this I will change it.