devatherock / ldap-search-api

Simple REST API to query a LDAP server
https://openapi-viewer.onrender.com?urls.primaryName=ldap-search-api
MIT License
11 stars 2 forks source link

Pretty print the JSON response #4

Closed devatherock closed 3 years ago

devatherock commented 3 years ago

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