jacksonobjectmapper

How to Configure Jackson to keep the Whitespace before a new Line


My App has a Web-Text input field. That data we store in the Database. When i show it again, the leading Whitespace are gone. I suspect the Jackson Object Mapper to make the mistake.

I use SpringBoot 3.0.6.

Input in the WebUI

enter image description here

DB View enter image description here

In the Debugger of the Java application before mapping it to the UI-DTO. enter image description here enter image description here

In the Browser i see the following enter image description here I

The ObjectMapper looks like this:

    @Bean
    public ObjectMapper objectMapper() {
        var objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JavaTimeModule());
        objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
        objectMapper.setSerializationInclusion(Include.NON_NULL);

        var p = new DefaultPrettyPrinter();
        Indenter i = new DefaultIndenter("  ", "\n");
        p.indentArraysWith(i);
        p.indentObjectsWith(i);
        objectMapper.setDefaultPrettyPrinter(p);

        return objectMapper;
    }

Does somebody knows how to configure the ObjectMapper to keep the Whitespace?


Solution

  • I made a mistake. The Code is correct and the With space are preserved. Do ignore this Question.