when serializing my resources on Jersey, I want to use namespaces in some cases.
Is 开发者_Go百科there any way to customize the namespace prefixes on jersey?
Default:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <order xmlns:ns2="http://www.w3.org/2005/Atom"> <price>123</price> <ns2:link rel="duh" href="/abc/123"/> <ns2:link rel="abc" href="/def/234"/> </order>
I want something like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <order xmlns:atom="http://www.w3.org/2005/Atom"> <price>123</price> <atom:link rel="duh" href="/abc/123"/> <atom:link rel="abc" href="/def/234"/> </order>
Thanks, Lucas
If you use the MOXy JAXB implementation you can control your prefixes using the @XmlSchema package level annotation:
@javax.xml.bind.annotation.XmlSchema(  
    xmlns = {  
          @javax.xml.bind.annotation.XmlNs(prefix = "atom", namespaceURI = "http://www.w3.org/2005/Atom")  
            })  
    package org.example.domain;  
To use MOXy JAXB you need to have a file named jaxb.properties in with your model classes with the following entry:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
For an example of using MOXy with Jersey see:
- http://bdoughan.blogspot.com/2010/08/creating-restful-web-service-part-35.html
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论