java 7 jaxb解组器与java 6不兼容

java 7 jaxb解组器与java 6不兼容,jaxb,java-7,java-6,Jaxb,Java 7,Java 6,我的应用程序在Java6中运行良好,但在我将java更新到版本7后,一些测试失败了。通过调试,我发现jaxb无法用Java7正确解析某些xml文件。这是我的代码: 用于测试的xml文件: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ma:recommendations xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ma="http://schemas.hy

我的应用程序在Java6中运行良好,但在我将java更新到版本7后,一些测试失败了。通过调试,我发现jaxb无法用Java7正确解析某些xml文件。这是我的代码:

用于测试的xml文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ma:recommendations xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ma="http://schemas.hyi.com/service/1.0"><responseTime>17</responseTime><requestId>MRECS-123a40a9-9cbe-4580-88a2-d88e86abcac8</requestId>
    <ma:recommendation>
        <id>pop1-a</id>
        <type></type>
        <name></name>
        <category></category>
        <rating>1.0</rating>
        <price></price>
        <currency></currency>
        <iconURI></iconURI>
        <downloadURI></downloadURI>
        <ratingCount></ratingCount>
        <downloadCount></downloadCount>
        <ma:extensions>
          <ma:extension ma:key="type">
            <ma:value>foo</ma:value>
          </ma:extension>
        </ma:extensions>
    </ma:recommendation>
</ma:recommendations>           
ExtensionMap.java

@XmlRootElement(namespace = XMLNamespace.URL)
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(namespace = XMLNamespace.URL)
public final class ExtensionMap extends HashMap<String, String> {
    /** Serialized version unique identifier. */
    private static final long serialVersionUID = -7235844731135521813L;

    /**
     * Default constructor to support JAXB binding.
     */
    public ExtensionMap() {
        super();
    }
    /**
     * Default constructor to support JAXB binding.
     * @param capacity The expected capacity of the map.
     */
    public ExtensionMap(int capacity) {
        super(capacity);
    }

    /**
     * The list of wrapped Map entries that are structured for binding to XML
     * with JAXB.
     * 
     * @return The list of wrapped Map entries that are structured for binding
     *         to XML with JAXB.
     */
    @XmlElement(name = "extension", namespace = XMLNamespace.URL, required = false)
    @SuppressWarnings("unused")
    private List<ExtensionMapElement> getEntries() {
        return new ListAdapter();
    }
    /**
     * The list of wrapped Map entries that are structured for binding to XML
     * with JAXB.
     * 
     * @param entries The list of wrapped Map entries that are structured for binding
     *         to XML with JAXB.
     */
    @SuppressWarnings("unused")
    private void setEntries(List<ExtensionMapElement> entries) {
        if (entries != null) {
            for (ExtensionMapElement entry : entries) {
                put(entry.getKey(), entry.getValue());
            }
        }
    }


    /**
     * Adapter for the list collection.
     * 
     */
    private class ListAdapter implements List<ExtensionMapElement> {

        @Override
        public boolean add(ExtensionMapElement e) {
            put(e.getKey(), e.getValue());
            return true;
        }

        @Override
        public void add(int index, ExtensionMapElement element) {
            add(element);
        }

        @Override
        public boolean addAll(Collection<? extends ExtensionMapElement> c) {
            if (c != null) {
                for (ExtensionMapElement element : c) {
                    add(element);
                }
            }
            return true;
        }

        @Override
        public boolean addAll(int index, Collection<? extends ExtensionMapElement> c) {
            addAll(c);
            return true;
        }

        @Override
        public void clear() {
            ExtensionMap.this.clear();
        }

        @Override
        public boolean contains(Object o) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean containsAll(Collection<?> c) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ExtensionMapElement get(int index) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public int indexOf(Object o) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isEmpty() {
            return ExtensionMap.this.isEmpty();
        }

        @Override
        public Iterator<ExtensionMapElement> iterator() {
            return new Iterator<ExtensionMapElement>() {
                private Iterator<Map.Entry<String, String>> _iter = ExtensionMap.this.entrySet().iterator();

                @Override
                public boolean hasNext() {
                    return _iter.hasNext();
                }

                @Override
                public ExtensionMapElement next() {
                    return new ExtensionMapElement(_iter.next());
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            };
        }

        @Override
        public int lastIndexOf(Object o) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ListIterator<ExtensionMapElement> listIterator() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ListIterator<ExtensionMapElement> listIterator(int index) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean remove(Object o) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ExtensionMapElement remove(int index) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean removeAll(Collection<?> c) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean retainAll(Collection<?> c) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ExtensionMapElement set(int index, ExtensionMapElement element) {
            add(element);
            return null;
        }

        @Override
        public int size() {
            return ExtensionMap.this.size();
        }

        @Override
        public List<ExtensionMapElement> subList(int fromIndex, int toIndex) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Object[] toArray() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T[] toArray(T[] a) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
}
/**
 * A utility type that wraps map entries to support a mapping between a
 * {@link java.util.Map} interface and a class that can be bound to XML using
 * JAXB.
 */
@XmlRootElement(namespace = XMLNamespace.URL)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = XMLNamespace.URL)
final class ExtensionMapElement implements Serializable {

    /**
     * Serialized version unique identifier.
     */
    private static final long serialVersionUID = 8211130122512683829L;

    /**
     * The key of the wrapped map entry.
     */
    @XmlAttribute(name = "key", namespace = XMLNamespace.URL, required = true)
    private String _key;

    /**
     * The value of the wrapped map entry.
     */
    @XmlElement(name = "value", namespace = XMLNamespace.URL, required = true)
    private String _value;

    /**
     * Default constructor to support JAXB Binding.
     */
    public ExtensionMapElement() {
    }

    /**
     * Wraps a map entry with an instance of this class.
     * 
     * @param e
     *            The map entry to wrap.
     */
    public ExtensionMapElement(Map.Entry<String, String> e) {
        _key = e.getKey();
        _value = e.getValue();
    }

    /**
     * The key of the wrapped map entry.
     * 
     * @return The key of the wrapped map entry.
     */
    public String getKey() {
        return _key;
    }

    /**
     * The value of the wrapped map entry.
     * 
     * @return The value of the wrapped map entry.
     */
    public String getValue() {
        return _value;
    }
}
@XmlRootElement(namespace=xmlnespace.URL)
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(namespace=xmlnespace.URL)
公共最终类ExtensionMap扩展HashMap{
/**序列化版本唯一标识符*/
私有静态最终长serialVersionUID=-7235844731135521813L;
/**
*支持JAXB绑定的默认构造函数。
*/
公共扩展映射(){
超级();
}
/**
*支持JAXB绑定的默认构造函数。
*@param capacity映射的预期容量。
*/
公共扩展映射(int容量){
超级(容量);
}
/**
*为绑定到XML而结构化的包装映射项列表
*使用JAXB。
* 
*@返回为绑定而构造的已包装映射项列表
*使用JAXB转换XML。
*/
@xmlement(name=“extension”,namespace=xmlnespace.URL,required=false)
@抑制警告(“未使用”)
私有列表getEntries(){
返回新的ListAdapter();
}
/**
*为绑定到XML而结构化的包装映射项列表
*使用JAXB。
* 
*@param entries为绑定而构造的包装映射项列表
*使用JAXB转换XML。
*/
@抑制警告(“未使用”)
私有无效集合项(列表项){
if(条目!=null){
for(ExtensionMapElement条目:条目){
put(entry.getKey(),entry.getValue());
}
}
}
/**
*列表集合的适配器。
* 
*/
私有类ListAdapter实现列表{
@凌驾
公共布尔添加(ExtensionMapElement e){
put(e.getKey(),e.getValue());
返回true;
}
@凌驾
public void add(int索引,ExtensionMapElement元素){
添加(元素);
}
@凌驾
公共布尔addAll(集合c){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共扩展插件get(int索引){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
public int indexOf(对象o){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共布尔值为空(){
返回ExtensionMap.this.isEmpty();
}
@凌驾
公共迭代器迭代器(){
返回新的迭代器(){
私有迭代器_iter=ExtensionMap.this.entrySet().Iterator();
@凌驾
公共布尔hasNext(){
return_iter.hasNext();
}
@凌驾
公共扩展插件next(){
返回新的ExtensionMapElement(_iter.next());
}
@凌驾
公共空间删除(){
抛出新的UnsupportedOperationException(“尚未支持”);
}
};
}
@凌驾
公共int lastIndexOf(对象o){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共ListIterator ListIterator(){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共ListIterator ListIterator(int索引){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共布尔删除(对象o){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共扩展插件删除(int索引){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共布尔removeAll(集合c){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共布尔保留(集合c){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共ExtensionMapElement集(int索引,ExtensionMapElement元素){
添加(元素);
返回null;
}
@凌驾
公共整数大小(){
返回ExtensionMap.this.size();
}
@凌驾
公共列表子列表(int fromIndex、int toIndex){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共对象[]toArray(){
抛出新的UnsupportedOperationException(“尚未支持”);
}
@凌驾
公共T[]toArray(T[]a){
抛出新的UnsupportedOperationException(“尚未支持”);
}
}
}
/**
*一种实用程序类型,它包装映射项以支持
*{@link java.util.Map}接口和一个可以使用
*JAXB。
*/
@XmlRootElement(名称空间=XMLNamespace.URL)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace=xmlnespace.URL)
最终类ExtensionMapElement实现了可序列化{
/**
*序列化版本唯一标识符。
*/
私有静态最终长serialVersionUID=8211130122512683829L;
/**
*包装映射项的键。
*/
@xmltattribute(name=“key”,namespace=xmlnespace.URL,required=true)
私钥;
/**
*包装映射项的值。
*/
@xmlement(name=“value”,namespace=xmlnespace.URL,必需=true)
私有字符串_值;
/**
*
@XmlRootElement(namespace = XMLNamespace.URL)
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(namespace = XMLNamespace.URL)
public final class ExtensionMap extends HashMap<String, String> {
    /** Serialized version unique identifier. */
    private static final long serialVersionUID = -7235844731135521813L;

    /**
     * Default constructor to support JAXB binding.
     */
    public ExtensionMap() {
        super();
    }
    /**
     * Default constructor to support JAXB binding.
     * @param capacity The expected capacity of the map.
     */
    public ExtensionMap(int capacity) {
        super(capacity);
    }

    /**
     * The list of wrapped Map entries that are structured for binding to XML
     * with JAXB.
     * 
     * @return The list of wrapped Map entries that are structured for binding
     *         to XML with JAXB.
     */
    @XmlElement(name = "extension", namespace = XMLNamespace.URL, required = false)
    @SuppressWarnings("unused")
    private List<ExtensionMapElement> getEntries() {
        return new ListAdapter();
    }
    /**
     * The list of wrapped Map entries that are structured for binding to XML
     * with JAXB.
     * 
     * @param entries The list of wrapped Map entries that are structured for binding
     *         to XML with JAXB.
     */
    @SuppressWarnings("unused")
    private void setEntries(List<ExtensionMapElement> entries) {
        if (entries != null) {
            for (ExtensionMapElement entry : entries) {
                put(entry.getKey(), entry.getValue());
            }
        }
    }


    /**
     * Adapter for the list collection.
     * 
     */
    private class ListAdapter implements List<ExtensionMapElement> {

        @Override
        public boolean add(ExtensionMapElement e) {
            put(e.getKey(), e.getValue());
            return true;
        }

        @Override
        public void add(int index, ExtensionMapElement element) {
            add(element);
        }

        @Override
        public boolean addAll(Collection<? extends ExtensionMapElement> c) {
            if (c != null) {
                for (ExtensionMapElement element : c) {
                    add(element);
                }
            }
            return true;
        }

        @Override
        public boolean addAll(int index, Collection<? extends ExtensionMapElement> c) {
            addAll(c);
            return true;
        }

        @Override
        public void clear() {
            ExtensionMap.this.clear();
        }

        @Override
        public boolean contains(Object o) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean containsAll(Collection<?> c) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ExtensionMapElement get(int index) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public int indexOf(Object o) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isEmpty() {
            return ExtensionMap.this.isEmpty();
        }

        @Override
        public Iterator<ExtensionMapElement> iterator() {
            return new Iterator<ExtensionMapElement>() {
                private Iterator<Map.Entry<String, String>> _iter = ExtensionMap.this.entrySet().iterator();

                @Override
                public boolean hasNext() {
                    return _iter.hasNext();
                }

                @Override
                public ExtensionMapElement next() {
                    return new ExtensionMapElement(_iter.next());
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            };
        }

        @Override
        public int lastIndexOf(Object o) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ListIterator<ExtensionMapElement> listIterator() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ListIterator<ExtensionMapElement> listIterator(int index) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean remove(Object o) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ExtensionMapElement remove(int index) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean removeAll(Collection<?> c) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean retainAll(Collection<?> c) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ExtensionMapElement set(int index, ExtensionMapElement element) {
            add(element);
            return null;
        }

        @Override
        public int size() {
            return ExtensionMap.this.size();
        }

        @Override
        public List<ExtensionMapElement> subList(int fromIndex, int toIndex) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Object[] toArray() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T[] toArray(T[] a) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
}
/**
 * A utility type that wraps map entries to support a mapping between a
 * {@link java.util.Map} interface and a class that can be bound to XML using
 * JAXB.
 */
@XmlRootElement(namespace = XMLNamespace.URL)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = XMLNamespace.URL)
final class ExtensionMapElement implements Serializable {

    /**
     * Serialized version unique identifier.
     */
    private static final long serialVersionUID = 8211130122512683829L;

    /**
     * The key of the wrapped map entry.
     */
    @XmlAttribute(name = "key", namespace = XMLNamespace.URL, required = true)
    private String _key;

    /**
     * The value of the wrapped map entry.
     */
    @XmlElement(name = "value", namespace = XMLNamespace.URL, required = true)
    private String _value;

    /**
     * Default constructor to support JAXB Binding.
     */
    public ExtensionMapElement() {
    }

    /**
     * Wraps a map entry with an instance of this class.
     * 
     * @param e
     *            The map entry to wrap.
     */
    public ExtensionMapElement(Map.Entry<String, String> e) {
        _key = e.getKey();
        _value = e.getValue();
    }

    /**
     * The key of the wrapped map entry.
     * 
     * @return The key of the wrapped map entry.
     */
    public String getKey() {
        return _key;
    }

    /**
     * The value of the wrapped map entry.
     * 
     * @return The value of the wrapped map entry.
     */
    public String getValue() {
        return _value;
    }
}