I'm configuring my ObjectMapper/XmlMessageConverter in Spring Boot with the following Beans:
@Bean
public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder()
{
final AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
return new Jackson2ObjectMapperBuilder().serializationInclusion(JsonInclude.Include.NON_NULL).defaultUseWrapper(false)
.annotationIntrospector(introspector);
}
@Bean
@Autowired
public MappingJackson2XmlHttpMessageConverter mappingJackson2XmlHttpMessageConverter(Jackson2ObjectMapperBuilder builder)
{
final XmlMapper xmlMapper = builder.createXmlMapper(true).build();
xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
xmlMapper.getFactory().getXMLOutputFactory().setProperty(WstxOutputProperties.P_USE_DOUBLE_QUOTES_IN_XML_DECL, true);
return new MappingJackson2XmlHttpMessageConverter(xmlMapper);
}
But I can't seem to find a way for force the output of standalone="yes" into the xml header.
Does anyone know how I can do this?
Looks like jackson can do it only with a (custom)
BufferingXmlWriter:But you have "spring alternatives":
Jaxb2RootElementHttpMessageConverterMarshallingHttpMessageConverterin combination with spring-oxm...can achieve it/have it as default.