-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Would like to be able to define a custom PrettyPrint class and have it used as the default by my ObjectMapper class. #689
Comments
I am not necessarily opposed to this, but out of curiosity: is it not feasible use and share Adding this setting in |
Its a valid question... We use a custom We bind it together using a spring Java configuration file like the following: @Configuration
public abstract class EntityResourceConfiguration extends BaseResourceConfiguration {
private JacksonJsonProvider jsonProvider(Class<? extends Entity> clazz) {
SimpleModule module = new SimpleModule();
module.addAbstractTypeMapping(Entity.class, clazz);
ObjectMapper mapper = new SmartObjectMapper(module);
return new JacksonJsonProvider(mapper);
}
...
} The default pretty printed JSON has some quirks we would like to tweak around how lists are formatted. We would like them to use the same |
To add my 2 cents: When I started using jackson, my feeling was that I should do everything via the I understand that it's simple to create your own But when I implemented it this way, I always felt "then what is the purpose of Looking at the design, I realize that Still, it feels like a skewed design. |
As I said earlier, excluding the fact that Being factory for readers/writers, it could still have defaults for instances. This is why I am not opposed to having direct method there. Thank you for all the comments. I can implement this for 2.6.0 then. |
I will see if there is a way to plugin just the readers and writers into the JacksonJsonProviders but so far we have always plugged in object mappers. I think I just assumed that since there is a |
I'll add the setter in 2.6.0, so that's fine. The last point I'll just mention is that |
Maybe to clarify my point: When I stepped through the code which For both reasons, I was very surprised when you suggested to create the |
@digulla Oh -- no, not directly instantiated at all. Indeed I would not recommend doing that. Unfortunate phrasing on my part. Used directly, not instantiated. The expected usage pattern is to create |
In the end implemented so that there is now method One thing worth noting is that one case where this does not work is if |
Thanks, the new API works fine for me. Re |
@digulla yes, at least documentation should reflect it. Question of method on |
I have a custom
MyObjectMapper
class and would like to have it use a customMyPrettyPrint
class as the default pretty printer everywhere one is used by the object mapper class. Ideally, I would like to be able to do something as simple as this:Currently, the ObjectMapper class generates new
DefaultPrettyPrinter
instances directly which limits the usefulness of overriding the_defaultPrettyPrinter
method.This enhancement request is a follow on to the discussion listed here.
The text was updated successfully, but these errors were encountered: