Jaxb를 사용하여 Java 클래스를 생성하고 있습니다. 당신이 볼 수 있듯이, 나는 자동차을 하나 개의 요소라고 한Jaxb가 생성 한 ObjectFactory를 사용하는 방법?
<xs:complexType name="AutomobileType" abstract="true">
<xs:sequence>
<xs:element name="Color" type="core:ColorName"/>
<xs:element name="Weight" type="core:PoundsWeightType"/>
<xs:element name="Fuel" type="Fuel"/>
<xs:element name="NumDoors" type="xs:nonNegativeInteger"/>
<xs:element name="NumCylinders">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="12"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="Automobile" type="AutomobileType"/>
: 내 스키마 정의 다음과 같은 요소를 가지고있다.
JAXB 클래스와 내가 자동차의 인스턴스를 생성하는 데 사용 ObjectFactory를을 만듭니다.
public JAXBElement<AutomobileType> createAutomobile(AutomobileType value)
가 왜 createAutomobile 방법은 인수가 않습니다 다음과 같이 나를 자동차의 인스턴스를 만들 수있는 방법이다 배플 것은 무엇입니까? 이 방법을 사용하려면 어떻게해야합니까?
ObjectFactory objectFactory = new ObjectFactory();
objectFactory.createAutomobile(new Automobile());
을하지만 자동차 클래스는 추상적이기 때문에이 컴파일되지 않으므로 내가 인스턴스를 만들 수 없습니다 :
나는 다음 시도했다.
Automobile 클래스를 Abstract가 아닌 것으로 변경했으며 모든 것이 이제는 정상적으로 작동합니다. 그러나 Automobile의 인스턴스를 마샬링하려고하면 다음과 같은 오류가 발생합니다. "com.cookmv.dealership.vehicles.schemas.automobile.AutomobileType"형식을 마샬링 할 수 없습니다. 요소가 @XmlRootElement 어노테이션이 없기 때문에 –