Re: JSON with XML Stream API/moshi

Jeff Greif <[email protected]> Tue, 18 Feb 2025 08:18:49 -0800
Newsgroups gmane.text.xml.axis.user
Message-ID <CABd_OhU9AgwU85=wSqywhbU+UBsEN7+FYTg+noddgdTeJ6HwTA@mail.gmail.com>
--0000000000009f85a2062e6cff31
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Disclaimer:  I don't have experience using Axis facilities for JSON.

There isn't a distinction between attributes and elements in JSON.
Essentially, every field is an attribute, but attributes may have complex
content.  So probably the JSON message should not use the '@' character to
distinguish an attribute.  Also, since order of fields is not significant
in JSON, XML schema concepts like <sequence> or "maxOccurs" may have no
fully corresponding JSON equivalent.

On Tue, Feb 18, 2025 at 7:40=E2=80=AFAM robertlazarski <robertlazarski@gmai=
l.com>
wrote:

> Could you please paste or attach your logs? That may help me understand
> the problem better. I don't have use cases combining XML and JSON in my o=
wn
> projects but I know the code pretty well and I can probably help.
>
> On Mon, Feb 17, 2025 at 5:23=E2=80=AFAM Stefan Traud <stefan_traud@yahoo.=
com>
> wrote:
>
>> Hi Robert
>> Using contract first with ADB, I continue to check feasibility to amend
>> our existing service with JSON support (based on XML Stream API with mos=
hi).
>>
>> I'm currently struggling with xml types that include attributes. To
>> reproduce the issue I have amended the wsdl in the samples.quickstartadb=
 to
>> include an attribute in the getPrice element:
>>
>> <xs:element name=3D"getPrice">
>>
>>     <xs:complexType>
>>
>>         <xs:sequence>
>>             <xs:element name=3D"symbol"
>>                 nillable=3D"true" type=3D"xs:string" />
>>
>>         </xs:sequence>
>>         <xs:attribute name=3D"currency"
>>             type=3D"xs:string" use=3D"required"/>
>>
>>     </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 "Requ=
ired
>> 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?
>>
>>
>>

--0000000000009f85a2062e6cff31
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Disclaimer:=C2=A0 I don&#39;t have experience using Axis f=
acilities for JSON.<div><br>There isn&#39;t a distinction between attribute=
s and elements in JSON.=C2=A0 Essentially, every field is an attribute, but=
 attributes may have complex content.=C2=A0 So probably=C2=A0the JSON messa=
ge should not use the &#39;@&#39; character to distinguish an attribute.=C2=
=A0 Also, since order of fields is not significant in JSON, XML schema conc=
epts like &lt;sequence&gt; or &quot;maxOccurs&quot; may have no fully corre=
sponding JSON equivalent.</div></div><br><div class=3D"gmail_quote gmail_qu=
ote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, Feb 18, 2025 a=
t 7:40=E2=80=AFAM robertlazarski &lt;<a href=3D"mailto:robertlazarski@gmail=
.com">[email protected]</a>&gt; wrote:<br></div><blockquote class=3D=
"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(2=
04,204,204);padding-left:1ex"><div dir=3D"ltr">Could you please paste or at=
tach your logs? That may help me understand the problem better. I don&#39;t=
 have use cases combining XML and JSON in my own projects but I know the co=
de pretty well and I can probably help. <br></div><br><div class=3D"gmail_q=
uote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, Feb 17, 2025 at 5:23=E2=
=80=AFAM Stefan Traud &lt;<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>&gt; wrote:<br></div><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid r=
gb(204,204,204);padding-left:1ex"><div><div style=3D"font-family:&quot;Helv=
etica Neue&quot;,Helvetica,Arial,sans-serif;font-size:13px"><div dir=3D"ltr=
">Hi Robert</div><div dir=3D"ltr">Using contract first with ADB, I continue=
 to check feasibility to amend our existing service with JSON support (base=
d on XML Stream API with moshi).</div><div dir=3D"ltr"><br></div><div dir=
=3D"ltr">I&#39;m currently struggling with xml types that include attribute=
s. To reproduce the issue I have amended the wsdl in the samples.quickstart=
adb to include an attribute in the getPrice element:</div><div dir=3D"ltr">=
<br></div><div dir=3D"ltr"><div><div style=3D"padding:0px 0px 0px 2px"><div=
 style=3D"color:rgb(0,0,0);font-family:Consolas;font-size:10pt"><p style=3D=
"margin:0px">			<span style=3D"color:rgb(0,128,128)">&lt;</span><span style=
=3D"color:rgb(63,127,127)">xs:element</span> <span style=3D"color:rgb(127,0=
,127)">name</span>=3D<span style=3D"color:rgb(42,0,255);font-style:italic">=
&quot;getPrice&quot;</span><span style=3D"color:rgb(0,128,128)">&gt;</span>=
</p><p style=3D"margin:0px">				<span style=3D"color:rgb(0,128,128)">=C2=A0=
=C2=A0=C2=A0=C2=A0&lt;</span><span style=3D"color:rgb(63,127,127)">xs:compl=
exType</span><span style=3D"color:rgb(0,128,128)">&gt;</span></p><p style=
=3D"margin:0px">					<span style=3D"color:rgb(0,128,128)">=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0&lt;</span><span style=3D"color:rgb(63,127=
,127)">xs:sequence</span><span style=3D"color:rgb(0,128,128)">&gt;</span></=
p><div style=3D"margin:0px"><span style=3D"color:rgb(0,128,128)">=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0&lt;</span><=
span style=3D"color:rgb(63,127,127)">xs:element</span> <span style=3D"color=
:rgb(127,0,127)">name</span>=3D<span style=3D"color:rgb(42,0,255);font-styl=
e:italic">&quot;symbol&quot;</span>=C2=A0</div><div style=3D"margin:0px"><s=
pan style=3D"color:rgb(127,0,127)">=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</span>=3D=
<span style=3D"color:rgb(42,0,255);font-style:italic">&quot;true&quot;=C2=
=A0</span><span style=3D"font-size:10pt;color:rgb(127,0,127)">type</span><s=
pan style=3D"font-size:10pt">=3D</span><span style=3D"font-size:10pt;color:=
rgb(42,0,255);font-style:italic">&quot;xs:string&quot;</span><span style=3D=
"font-size:10pt"> </span><span style=3D"font-size:10pt;color:rgb(0,128,128)=
">/&gt;</span></div><p style=3D"margin:0px">					<span style=3D"color:rgb(0=
,128,128)">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0&lt;/</span><spa=
n style=3D"color:rgb(63,127,127)">xs:sequence</span><span style=3D"color:rg=
b(0,128,128)">&gt;</span></p><div style=3D"margin:0px"><span style=3D"color=
:rgb(0,128,128)">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0&lt;</span=
><span style=3D"color:rgb(63,127,127)">xs:attribute</span> <span style=3D"c=
olor:rgb(127,0,127)">name</span>=3D<span style=3D"color:rgb(42,0,255);font-=
style:italic">&quot;currency&quot;</span>=C2=A0</div><div style=3D"margin:0=
px"><span style=3D"color:rgb(127,0,127)">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0type</span>=3D<span style=3D"color:r=
gb(42,0,255);font-style:italic">&quot;xs:string&quot;</span> <span style=3D=
"color:rgb(127,0,127)">use</span>=3D<span style=3D"color:rgb(42,0,255);font=
-style:italic">&quot;required&quot;</span><span style=3D"color:rgb(0,128,12=
8)">/&gt;</span></div><p style=3D"margin:0px">				<span style=3D"color:rgb(=
0,128,128)">=C2=A0=C2=A0=C2=A0=C2=A0&lt;/</span><span style=3D"color:rgb(63=
,127,127)">xs:complexType</span><span style=3D"color:rgb(0,128,128)">&gt;</=
span></p><p style=3D"margin:0px">			<span style=3D"color:rgb(0,128,128)">&l=
t;/</span><span style=3D"color:rgb(63,127,127)">xs:element</span><span styl=
e=3D"color:rgb(0,128,128)">&gt;</span></p></div></div></div><br></div><div =
dir=3D"ltr">My corresponding JSON message should then be something like:</d=
iv><div dir=3D"ltr"><br></div><div dir=3D"ltr">{ &quot;getPrice&quot; : {&q=
uot;@currency&quot;: &quot;USD&quot;, &quot;symbol&quot;: &quot;IBM&quot; }=
}</div><div dir=3D"ltr"><br></div><div dir=3D"ltr">However the parse method=
 in the GetPrice ADBBean keeps complaining &quot;<span><span style=3D"paddi=
ng:0px 0px 0px 2px"><span style=3D"color:rgb(0,0,0);font-family:Consolas;fo=
nt-size:10pt">Required attribute currency is missing</span></span></span>&q=
uot;; specifically this call returns null:</div><div dir=3D"ltr"><br></div>=
<div dir=3D"ltr"><div><div style=3D"padding:0px 0px 0px 2px"><div style=3D"=
color:rgb(0,0,0);font-family:Consolas;font-size:10pt"><div style=3D"margin:=
0px"><span style=3D"color:rgb(106,62,62)">reader</span>.getAttributeValue(<=
span style=3D"color:rgb(42,0,255)">&quot;<a href=3D"http://quickstart.sampl=
es/xsd" target=3D"_blank">http://quickstart.samples/xsd</a>&quot;</span>, <=
span style=3D"color:rgb(42,0,255)">&quot;currency&quot;</span>);</div><div =
style=3D"margin:0px"><br></div></div></div></div>(However it works when usi=
ng SOAP).</div><div dir=3D"ltr"><br></div><div dir=3D"ltr">Do I need to def=
ine attributes differently in the JSON message?</div><div dir=3D"ltr"><br><=
/div><div dir=3D"ltr"><br></div></div></div></blockquote></div>
</blockquote></div>

--0000000000009f85a2062e6cff31--