How to get formatted xml output from jaxb in spring?

后端 未结 6 2290
陌清茗
陌清茗 2020-12-29 20:38

I am using Jaxb2Marshaller as a view property for ContentNegotiatingViewResolver. I am able to get the xml repsonse. How do I format (pretty print) it?



        
6条回答
  •  时光取名叫无心
    2020-12-29 21:01

    Was looking for this and thought I'd share the code equivalent

    @Bean
    public Marshaller jaxbMarshaller() {
        Map props = new HashMap();
        props.put(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    
        Jaxb2Marshaller m = new Jaxb2Marshaller();
        m.setMarshallerProperties(props);
        m.setPackagesToScan("com.example.xml");
        return m;
    }
    

提交回复
热议问题