java xml 静态对象_当存在静态类时,没有带有@XmlElementDecl的ObjectFactory

I am getting below exception, i need some help to resolve the issue.

If remove the namespace in the object factory and with out package-info.java class it is working fine.

Exception that is throwing now

Exception in thread "main" com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions

There's no ObjectFactory with an @XmlElementDecl for the element {}shipping.

this problem is related to the following location:

at protected javax.xml.bind.JAXBElement com.jverstry.annotations.generics.Market$Detail.shipping

at com.jverstry.annotations.generics.Market$Detail

at protected com.jverstry.annotations.generics.Market$Detail com.jverstry.annotations.generics.Market.detail

at com.jverstry.annotations.generics.Market

正在创建jaxbelement的ObjectFactory类

package com.jverstry.annotations.generics;

import javax.xml.bind.JAXBElement;

import javax.xml.bind.annotation.XmlElementDecl;

import javax.xml.bind.annotation.XmlRegistry;

import javax.xml.namespace.QName;

import org.example.customer.Customer;

@XmlRegistry

public class ObjectFactory {

public ObjectFactory() {

}

public Market.Detail.Shipping createShipping() {

return new Market.Detail.Shipping();

}

private final static QName _Shipping_QNAME = new QName("http://www.example.org/customer", "shipping");

@XmlElementDecl(namespace = "http://www.example.org/customer", name = "shipping")

public JAXBElement createShipping(Market.Detail.Shipping value) {

return new JAXBElement(_Shipping_QNAME, Market.Detail.Shipping.class, value);

}

}

类package-info.java,其中为响应xml提及名称空间

@XmlSchema(namespace = "http://www.example.org/customer", elementFormDefault = XmlNsForm.QUALIFIED)

package com.jverstry.annotations.generics;

import javax.xml.bind.annotation.*;

演示类所在的编组对象

package com.jverstry.annotations.generics;

import javax.xml.bind.JAXBContext;

import javax.xml.bind.JAXBElement;

import javax.xml.bind.Marshaller;

public class Demo {

public static void main(String[] args) throws Exception {

JAXBContext jc = JAXBContext.newInstance(Market.class);

Market market = new Market();

Market.Detail md = new Market.Detail();

Market.Detail.Shipping mds = new Market.Detail.Shipping();

mds.setAvailable(false);

JAXBElement shipping = new ObjectFactory().createShipping(mds);

shipping.setNil(true);

md.setShipping(shipping);

market.setDetail(md);

Marshaller marshaller = jc.createMarshaller();

marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

marshaller.marshal(market, System.out);

}

}

市场类,这是创建jaxbcontext的主要根类

package com.jverstry.annotations.generics;

import java.math.BigDecimal;

import javax.xml.bind.JAXBElement;

import javax.xml.bind.annotation.*;

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "", propOrder = { "detail" })

@XmlRootElement(name = "Market")

public class Market

{

@XmlElement(required = false)

protected Market.Detail detail;

public Market.Detail getDetail() {

return detail;

}

public void setDetail(Market.Detail detail) {

this.detail = detail;

}

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "", propOrder = { "shipping" })

public static class Detail

{

@XmlElementRef(name = "shipping")

protected JAXBElement shipping;

public JAXBElement getShipping() {

return shipping;

}

public void setShipping(JAXBElement value) {

this.shipping = value;

}

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "", propOrder = { "value" })

public static class Shipping

{

@XmlValue

protected BigDecimal value;

@XmlAttribute(name = "available")

protected Boolean available;

public BigDecimal getValue() {

return value;

}

public void setValue(BigDecimal value) {

this.value = value;

}

public Boolean getAvailable() {

return available;

}

public void setAvailable(Boolean value) {

this.available = value;

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值