-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow Jackson configuration through properties #18572
Comments
I think this is a nice enhancement and we actually already do this for |
/cc @gsmet |
I'll do this after #20468 is in |
There is one thing I don't like however about the proposal: It is not conductive to auto-completion by IDEs because the feature names are simply strings. |
I think the downside though is anytime there is a new config property in Jackson then Quarkus needs to make a change and "catch up", whereas them just being Strings allows users to use new features as they become available without Quarkus needing to make any changes. That being said I don't know the internal implementation, so it may not be a big deal. |
Yeah, that's the price to pay for sure. |
Do you really want to have to remember to update Quarkus config/tests/etc every time Jackson makes an update? Thats the real question. Me personally I would prefer convention where I don't have to touch framework code if a library that the framework uses makes a change. But that's me and I'm not implementing this :) Just my $0.02. |
We always have to think about developer joy though as well 😉 |
As a developer I would have much joy if new things in Jackson just worked without me having to file a ticket to have some property implemented/recognized by Quarkus :D |
Hey @geoand gentle ping on this...thoughts? I'm up for trying out a PR for this if you can point me to where I might get started? |
Thanks thats helpful! Are there tests anywhere that test that the |
I'll throw a draft PR together shortly for your to take a look at |
Cool :) |
Ahh seems I can't do this in /**
* Enable/disable Jackson serialization ({@code com.fasterxml.jackson.databind.SerializationFeature}) features.
*/
@ConfigItem
public Map<SerializationFeature, Boolean> serialization = new EnumMap<>(SerializationFeature.class);
/**
* Enable/disable Jackson deserialization ({@code com.fasterxml.jackson.databind.DeserializationFeature}) features.
*/
@ConfigItem
public Map<DeserializationFeature, Boolean> deserialization = new EnumMap<>(DeserializationFeature.class);
/**
* Enable/disable Jackson general purpose mapping ({@code com.fasterxml.jackson.databind.MapperFeature}) features.
*/
@ConfigItem
public Map<MapperFeature, Boolean> mapper = new EnumMap<>(MapperFeature.class);
/**
* Enable/disable Jackson parser ({@code com.fasterxml.jackson.core.JsonParser.Feature}) features.
*/
@ConfigItem
public Map<JsonParser.Feature, Boolean> parser = new EnumMap<>(JsonParser.Feature.class);
/**
* Enable/disable Jackson generator ({@code com.fasterxml.jackson.core.JsonGenerator.Feature}) features.
*/
@ConfigItem
public Map<JsonGenerator.Feature, Boolean> generator = new EnumMap<>(JsonGenerator.Feature.class); |
You mean have an enum as the key of the map? If so, then correct, you can't |
Yes thats what I mean. I would think this would be a common thing no? Couldn't we modify if (keyClass != String.class) {
throw reportError(field, "Map key types other than String are not yet supported");
} ? |
Yes, it can be done, although no it's not common - no one has asked for it AFAIK in the 3 years Quarkus has been around |
take you what? an hour or so? :D |
My guess is that it's a one liner 😜. I'll have a look tomorrow |
I changed that if ((keyClass != String.class) && !keyClass.isEnum()) {
throw reportError(field, "Map key types other than String and Enum are not yet supported");
} but no idea if that fixes it :) I'll play with it and see if my tests work :) |
😎 |
Unfortunately that in itself doesn't seem to do it. Seems that the config class ( The Lines 691 to 698 in 60426de
I'm not sure I understand enough of how the config parsing works to be able to take this on. Do you want me to create a separate ticket for this? |
Sure yeah |
I created ##24214 |
It might just be me but I don't see how it is more practical than a customizer given you don't have any completion so you will somehow have to go in the doc to find the right name, whereas you can just use completion with a customizer. It's a bit more code but it's more flexible and less brittle. And bonus point: you know when a feature is deprecated at compile time. I could see an interest in that if we exposed and documented the most useful configuration properties as we started to do it but a free form thing, I don't know. |
I'm not sure what you mean by |
@gsmet means an ObjectMapperCustomizer. |
Yeah I was just in the middle of writing that |
Description
It would be nice to be able to configure the Jackson
ObjectMapper
through properties rather than having to create a class extendingObjectMapperCustomizer
.Rather than having to constantly map Quarkus-specific properties to Jackson properties, just allow free-form mapping within the properties that would "flow-through" to the underlying Jackson enum properties. Something like this:
com.fasterxml.jackson.databind.DeserializationFeature
quarkus.jackson.deserialization.<feature_name>
true
,false
com.fasterxml.jackson.databind.SerializationFeature
quarkus.jackson.serialization.<feature_name>
true
,false
com.fasterxml.jackson.databind.MapperFeature
quarkus.jackson.mapper.<feature_name>
true
,false
com.fasterxml.jackson.core.JsonGenerator.Feature
quarkus.jackson.generator.<feature_name>
true
,false
com.fasterxml.jackson.core.JsonParser.Feature
quarkus.jackson.parser.<feature_name>
true
,false
com.fasterxml.jackson.annotation.JsonInclude.Include
quarkus.jackson.default-property-inclusion
always
,non_null
,non_absent
,non_default
,non_empty
This way, if/as new "things" are added to the enums, there isn't any work that needs to be done in the extension. As long as
<feature_name>
aligns with the enum constant, it would just map.I would envision these properties would be fixed at build time and not overridable at runtime. We'd have to decide what to do in the case that an application provides an
ObjectMapperCustomizer
and there are properties set. I would think that we would union the properties and what is defined in theObjectMapperCustomizer
. We'd have to figure out "who wins" in the situation where a property is set to one value and the customizer sets a different value for the same enum property. Don't property values specified inapplication.properties
/application.yml
always "win" over whats in the code?The text was updated successfully, but these errors were encountered: