Skip to content
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

Pretty print the JSON response #4

Closed
devatherock opened this issue Dec 20, 2020 · 1 comment
Closed

Pretty print the JSON response #4

devatherock opened this issue Dec 20, 2020 · 1 comment

Comments

@devatherock
Copy link
Owner

No description provided.

devatherock added a commit that referenced this issue Dec 20, 2020
Documented config that enables pretty JSON - closes #4
@devatherock devatherock reopened this Dec 20, 2020
@devatherock
Copy link
Owner Author

Setting jackson.serialization.indent-output to true does not indent arrays. Need additional configuration to enable array indentation.

   @Singleton
    static class ObjectMapperBeanEventListener implements BeanCreatedEventListener<ObjectMapper> {

        @Override
        public ObjectMapper onCreated(BeanCreatedEvent<ObjectMapper> event) {
            final ObjectMapper objectMapper = event.getBean();
            DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
            prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE);
            objectMapper.setDefaultPrettyPrinter(prettyPrinter);

            return objectMapper;
        }
    }

References:
https://stackoverflow.com/questions/53195071/how-to-configure-jackson-to-use-snake-case-in-micronaut
https://stackoverflow.com/questions/17411586/jackson-json-not-formatting-correctly/17415099
https://stackoverflow.com/questions/28256852/what-is-the-simplest-way-to-configure-the-indentation-spacing-on-a-jackson-objec
https://www.endpoint.com/blog/2020/03/17/serialization-issues-spring-rest

devatherock added a commit that referenced this issue Dec 20, 2020
Customized the pretty printer to indent arrays - closes #4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant