JSON with XML Stream API/moshi

Stefan Traud <[email protected]> Mon, 17 Feb 2025 15:23:45 +0000 (UTC)
Newsgroups gmane.text.xml.axis.user
Message-ID <[email protected]>
------=_Part_1056567_844019797.1739805825837
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi RobertUsing contract first with ADB, I continue to check feasibility to =
amend our existing service with JSON support (based on XML Stream API with =
moshi).
I'm currently struggling with xml types that include attributes. To reprodu=
ce the issue I have amended the wsdl in the samples.quickstartadb to includ=
e an attribute in the getPrice element:

 <xs:element name=3D"getPrice">

 =C2=A0=C2=A0=C2=A0=C2=A0<xs:complexType>

 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<xs:sequence>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<xs=
:element name=3D"symbol"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0nillable=3D"true"=C2=A0t=
ype=3D"xs:string" />
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0</xs:sequence>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<xs:attribute name=3D"curre=
ncy"=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0type=3D"xs:string" use=3D"required"/>
 =C2=A0=C2=A0=C2=A0=C2=A0</xs:complexType>

 </xs:element>

My corresponding JSON message should then be something like:
{ "getPrice" : {"@currency": "USD", "symbol": "IBM" }}
However the parse method in the GetPrice ADBBean keeps complaining "Require=
d attribute currency is missing"; specifically this call returns null:
reader.getAttributeValue("http://quickstart.samples/xsd", "currency");
(However it works when using SOAP).
Do I need to define attributes differently in the JSON message?


------=_Part_1056567_844019797.1739805825837
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html><head></head><body><div class=3D"yahoo-style-wrap" style=3D"font-fami=
ly:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div dir=
=3D"ltr" data-setdir=3D"false">Hi Robert</div><div dir=3D"ltr" data-setdir=
=3D"false">Using contract first with ADB, I continue to check feasibility t=
o amend our existing service with JSON support (based on XML Stream API wit=
h moshi).</div><div dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=3D=
"ltr" data-setdir=3D"false">I'm currently struggling with xml types that in=
clude attributes. To reproduce the issue I have amended the wsdl in the sam=
ples.quickstartadb to include an attribute in the getPrice element:</div><d=
iv dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=3D"ltr" data-setdir=
=3D"false"><div><div style=3D"padding: 0px 0px 0px 2px;"><div style=3D"colo=
r: rgb(0, 0, 0); font-family: Consolas; font-size: 10pt;"><p style=3D"margi=
n:0;">=09=09=09<span style=3D"color:#008080;">&lt;</span><span style=3D"col=
or:#3f7f7f;">xs:element</span> <span style=3D"color:#7f007f;">name</span>=
=3D<span style=3D"color:#2a00ff;font-style:italic;">"getPrice"</span><span =
style=3D"color:#008080;">&gt;</span></p><p style=3D"margin:0;">=09=09=09=09=
<span style=3D"color:#008080;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span sty=
le=3D"color:#3f7f7f;">xs:complexType</span><span style=3D"color:#008080;">&=
gt;</span></p><p style=3D"margin:0;">=09=09=09=09=09<span style=3D"color:#0=
08080;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span st=
yle=3D"color:#3f7f7f;">xs:sequence</span><span style=3D"color:#008080;">&gt=
;</span></p><div style=3D"margin:0;"><span style=3D"color:#008080;">&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span=
><span style=3D"color:#3f7f7f;">xs:element</span> <span style=3D"color:#7f0=
07f;">name</span>=3D<span style=3D"color:#2a00ff;font-style:italic;">"symbo=
l"</span>&nbsp;</div><div style=3D"margin:0;"><span style=3D"color:#7f007f;=
">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;nillable</span>=3D<span style=3D"color:#2a00ff;font-=
style:italic;">"true"&nbsp;</span><span style=3D"font-size: 10pt; color: rg=
b(127, 0, 127);">type</span><span style=3D"font-size: 10pt;">=3D</span><spa=
n style=3D"font-size: 10pt; color: rgb(42, 0, 255); font-style: italic;">"x=
s:string"</span><span style=3D"font-size: 10pt;"> </span><span style=3D"fon=
t-size: 10pt; color: rgb(0, 128, 128);">/&gt;</span></div><p style=3D"margi=
n:0;">=09=09=09=09=09<span style=3D"color:#008080;">&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/</span><span style=3D"color:#3f7f7f;">xs:sequ=
ence</span><span style=3D"color:#008080;">&gt;</span></p><div style=3D"marg=
in:0;"><span style=3D"color:#008080;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&lt;</span><span style=3D"color:#3f7f7f;">xs:attribute</span> <s=
pan style=3D"color:#7f007f;">name</span>=3D<span style=3D"color:#2a00ff;fon=
t-style:italic;">"currency"</span>&nbsp;</div><div style=3D"margin:0;"><spa=
n style=3D"color:#7f007f;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;type</span>=3D<span style=3D"color:#2a00ff;font-sty=
le:italic;">"xs:string"</span> <span style=3D"color:#7f007f;">use</span>=3D=
<span style=3D"color:#2a00ff;font-style:italic;">"required"</span><span sty=
le=3D"color:#008080;">/&gt;</span></div><p style=3D"margin:0;">=09=09=09=09=
<span style=3D"color:#008080;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/</span><span st=
yle=3D"color:#3f7f7f;">xs:complexType</span><span style=3D"color:#008080;">=
&gt;</span></p><p style=3D"margin:0;">=09=09=09<span style=3D"color:#008080=
;">&lt;/</span><span style=3D"color:#3f7f7f;">xs:element</span><span style=
=3D"color:#008080;">&gt;</span></p></div></div></div><br></div><div dir=3D"=
ltr" data-setdir=3D"false">My corresponding JSON message should then be som=
ething like:</div><div dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=
=3D"ltr" data-setdir=3D"false">{ "getPrice" : {"@currency": "USD", "symbol"=
: "IBM" }}</div><div dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=
=3D"ltr" data-setdir=3D"false">However the parse method in the GetPrice ADB=
Bean keeps complaining "<span><span style=3D"padding: 0px 0px 0px 2px;"><sp=
an style=3D"color: rgb(0, 0, 0); font-family: Consolas; font-size: 10pt;">R=
equired attribute currency is missing</span></span></span>"; specifically t=
his call returns null:</div><div dir=3D"ltr" data-setdir=3D"false"><br></di=
v><div dir=3D"ltr" data-setdir=3D"false"><div><div style=3D"padding: 0px 0p=
x 0px 2px;"><div style=3D"color: rgb(0, 0, 0); font-family: Consolas; font-=
size: 10pt;"><div style=3D"margin:0;"><span style=3D"color:#6a3e3e;">reader=
</span>.getAttributeValue(<span style=3D"color:#2a00ff;">"http://quickstart=
.samples/xsd"</span>, <span style=3D"color:#2a00ff;">"currency"</span>);</d=
iv><div style=3D"margin:0;"><br></div></div></div></div>(However it works w=
hen using SOAP).</div><div dir=3D"ltr" data-setdir=3D"false"><br></div><div=
 dir=3D"ltr" data-setdir=3D"false">Do I need to define attributes different=
ly in the JSON message?</div><div dir=3D"ltr" data-setdir=3D"false"><br></d=
iv><div dir=3D"ltr" data-setdir=3D"false"><br></div></div></body></html>
------=_Part_1056567_844019797.1739805825837--