有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将在jaxb中创建objectfactory实例

我是Jaxb的新手。我对对象工厂有一个疑问。问题在于,当调用解组过程时,它何时会在objectfactory类createXXXBean方法中创建bean实例。查看下面的objectfactory。createFruitbean()

  @XmlElementDecl(namespace = "http://as.com/items/types", name = "fruitbean")
    public JAXBElement<Fruittype> createFruitbean(Fruittype value) {

        return new JAXBElement<Fruittype>(_Fruitbean_QNAME, Fruittype.class, null, value);
    }

请帮帮我

更新:-

我没有得到任何关于上述代码的解释。我对ObjectFactory有怀疑。createFruitBean()。在下面的代码片段中,它将在何处/何时调用方法,即ObjectFactory。createFruitbean()

JAXBContext jContext=JAXBContext.newInstance(ObjectFactory.class);
UnMarshaller unmarshall=jContext.CreateMarshaller();
JAXBElement jElement=unmarshall.UnMarshall(XML_PATH);

共 (1) 个答案

  1. # 1 楼答案

    @XmlRegistry
    public class ObjectFactory {
    
       private static final QName FRUIT_QNAME = new QName("...", "...");
    
       public ObjectFactory() {
       }
    
       public Fruittype createFruittype() {
          return new Fruittype();
       }
    
       @XmlElementDecl(namespace = "http://as.com/items/types", name = "fruitbean")
       public JAXBElement<Fruittype> createFruitbean(Fruittype value) {
          return new JAXBElement<Fruittype>(_Fruitbean_QNAME, Fruittype.class, null, value);
       }
    }