JAXB:要素はプロパティではなくタイプにちなんで命名されます

StackOverflow https://stackoverflow.com/questions/1443863

  •  22-07-2019
  •  | 
  •  

質問

Webサービスwsdlには次のスキーマが含まれています:

<xs:complexType name="DocumentSearchInfo">
    <xs:sequence>
     ...
       <xs:element minOccurs="0" name="Industries" nillable="true" type="tns:ListCondition">
        <xs:annotation>
          <xs:appinfo>
            <DefaultValue EmitDefaultValue="false" xmlns="http://schemas.microsoft.com/2003/10/Serialization/" />
          </xs:appinfo>
        </xs:annotation>
       </xs:element>
   ...
    </xs:sequence>
  </xs:complexType>

このコードは、NetBeans 6.7でWeb参照を追加して生成されました。

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DocumentSearchInfo", propOrder = {
    "analysts",
    "companyIDCondition",
    "contributorCondition",
    "countries",
    "dateRange",
    "documentIDCondition",
    "documentPageCondition",
    "industries",
    "keywordCondition",
    "languages",
    "profileID",
    "purchasedOnly",
    "regions",
    "researchCategories",
    "researchProduct"
})

    public class DocumentSearchInfo {
    ...
      @XmlElementRef(name = "Industries", namespace = "http://somenshere", type = JAXBElement.class)
        protected JAXBElement<ListCondition> industries;
    ...
    }

次に、シリアル化されます

<ns2:SearchInfo>
 ...
   <ns2:ListCondition>
     <ns2:Values>
       <ns3:string>1385</ns3:string>
       <ns3:string>1386</ns3:string>
     </ns2:Values>
   </ns2:ListCondition>
 ...
</ns2:SearchInfo>

このXMLには「ListCondition」ではなく「Industries」が表示されることを期待しています。

.netでこのサービスを使用するのに問題はありませんでした:svcutilとwsdl.exeの両方は、使用するシリアライザーに関係なく正常に動作しますが、Javaでのシリアル化について明らかな何かを見逃しているようです。

誰でも助けてもらえますか?

役に立ちましたか?

解決

解決済み。 ObjectFactoryのcreateDocumentSearchInfoIndustriesメソッドを呼び出す必要がありました。 .netで慣れていたものとは非常に異なります)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top