Document size too big to print

In our project we have following issue, we try to print a document with huge number of repetitions over 4000. This leeds to following, is there configuration or a work around ?

Warning: You did not close a PDF Document",“logger_name”:"org.apache.pdfbox.cos.COSDocument

com.fasterxml.jackson.core.exc.StreamConstraintsException: String value length (20054016) exceeds the maximum allowed (20000000)

Hey Kosta :slight_smile:

We had a similar problem in our application and ended up creating a configuration to override the maximum string length in all object mappers in a service.

The config class:

@Configuration
public class ObjectMapperConfig {

    @Value("<config.name>: <default value>}")
    private Integer stringLength;

    public void setMaxStringLength() {
        StreamReadConstraints.overrideDefaultStreamReadConstraints(StreamReadConstraints.builder().maxStringLength(stringLength).build());
    }
}

How to set the value for the whole service:

@SpringBootApplication
@ComponentScan({"<package.with.config.class>"}
public class BapServer extends SpringBootServletInitializer {

    LottaaBapServer(ObjectMapperConfig config) {
        // loading this config here so that all newly created object mappers have the configured max string read length
        config.setMaxStringLength();
    }

    public static void main(String[] args) {
        final SpringApplication application = new SpringApplication(BapServer.class);
        application.run(args).start();
    }
}

If you only want to increase the string size of http requests, there is the option to provide a MappingJackson2HttpMessageConverter.

I hope this approach is applicable for your use case :slight_smile:

Best regards,
Gero