Anyway to pass a constructor parameter to a JAXB Adapter?

前端 未结 2 749
一生所求
一生所求 2021-02-20 08:45

I\'m using Spring 3 IOC and JAXB/JAX-WS in a WebService that I wrote. I am having a slight issue right now with data that must be rounded prior to returning to the consumer as

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-20 09:05

    I'm not sure how you hook this in with Spring, but below is a description of the JAXB mechanism that you can leverage.

    If you have the following:

    @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(value=RoundingAdapter.class,type=java.math.BigDecimal.class)
    

    Then using the standalone JAXB APIs you could do the following. The code below means whenever the RoundingAdapter is encountered, the specified instance should be used.

    marshaller.setAdapter(new RoundingAdapter(4));
    unmarshaller.setAdapter(new RoundingAdapter(4));
    

    For More Information

    • http://blog.bdoughan.com/2011/09/mixing-nesting-and-references-with.html

提交回复
热议问题