Re: JSON with XML Stream API/moshi
Stefan Traud <[email protected]> Wed, 19 Feb 2025 09:02:21 +0000 (UTC)
| Newsgroups | gmane.text.xml.axis.user |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_1891485_1918280389.1739955741036
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Thanks for your feedback. Since xml attributes do not have a correspondanc=
e in json, I would expect that there are conventions on how to handle these=
.For example, when experimenting with mapped JSON, the generated soap messa=
ge is properly populated with attributes from the json string when using th=
e "@" prefix (this is using libraries from jettison). Unfortunately I do no=
t know the convention for xml attributes when using the XML Stream API with=
moshi, nor whether this is supported at all.
Am Dienstag, 18. Februar 2025 um 17:19:01 MEZ hat Jeff Greif <jgreif@al=
umni.princeton.edu> Folgendes geschrieben: =20
=20
Disclaimer:=C2=A0 I don't have experience using Axis facilities for JSON.
There isn't a distinction between attributes and elements in JSON.=C2=A0 Es=
sentially, every field is an attribute, but attributes may have complex con=
tent.=C2=A0 So probably=C2=A0the JSON message should not use the '@' charac=
ter to distinguish an attribute.=C2=A0 Also, since order of fields is not s=
ignificant 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 own pr=
ojects but I know the code pretty well and I can probably help.=20
On Mon, Feb 17, 2025 at 5:23=E2=80=AFAM Stefan Traud <[email protected]=
m> wrote:
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?
=20
------=_Part_1891485_1918280389.1739955741036
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html><head></head><body><div class=3D"ydp8b0b66d7yahoo-style-wrap" style=
=3D"font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px=
;"><div></div>
<div dir=3D"ltr" data-setdir=3D"false">Thanks for your feedback. Si=
nce xml attributes do not have a correspondance in json, I would expect tha=
t there are conventions on how to handle these.</div><div dir=3D"ltr" data-=
setdir=3D"false">For example, when experimenting with mapped JSON, the gene=
rated soap message is properly populated with attributes from the json stri=
ng when using the "@" prefix (this is using libraries from jettison). Unfor=
tunately I do not know the convention for xml attributes when using the XML=
Stream API with moshi, nor whether this is supported at all.</div><div><br=
></div>
=20
</div><div id=3D"yahoo_quoted_0577958227" class=3D"yahoo_quoted">
<div style=3D"font-family:'Helvetica Neue', Helvetica, Arial, s=
ans-serif;font-size:13px;color:#26282a;">
=20
<div>
Am Dienstag, 18. Februar 2025 um 17:19:01 MEZ hat J=
eff Greif <[email protected]> Folgendes geschrieben:
</div>
<div><br></div>
<div><br></div>
=20
=20
<div><div id=3D"yiv9798084774"><div><div dir=3D"ltr">Discla=
imer: I don't have experience using Axis facilities for JSON.<div><br=
clear=3D"none">There isn't a distinction between attributes and elements i=
n JSON. Essentially, every field is an attribute, but attributes may =
have complex content. So probably the JSON message should not us=
e the '@' character to distinguish an attribute. Also, since order of=
fields is not significant in JSON, XML schema concepts like <sequence&g=
t; or "maxOccurs" may have no fully corresponding JSON equivalent.</div></d=
iv><br clear=3D"none"><div id=3D"yiv9798084774yqt03945" class=3D"yiv9798084=
774yqt2509777967"><div class=3D"yiv9798084774gmail_quote yiv9798084774gmail=
_quote_container"><div dir=3D"ltr" class=3D"yiv9798084774gmail_attr">On Tue=
, Feb 18, 2025 at 7:40=E2=80=AFAM robertlazarski <<a rel=3D"nofollow noo=
pener noreferrer" shape=3D"rect" ymailto=3D"mailto:[email protected]=
" target=3D"_blank" href=3D"mailto:[email protected]">robertlazarski=
@gmail.com</a>> wrote:<br clear=3D"none"></div><blockquote style=3D"marg=
in:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1e=
x;" class=3D"yiv9798084774gmail_quote"><div dir=3D"ltr">Could you please pa=
ste or attach your logs? That may help me understand the problem better. I =
don't have use cases combining XML and JSON in my own projects but I know t=
he code pretty well and I can probably help. <br clear=3D"none"></div><br c=
lear=3D"none"><div class=3D"yiv9798084774gmail_quote"><div dir=3D"ltr" clas=
s=3D"yiv9798084774gmail_attr">On Mon, Feb 17, 2025 at 5:23=E2=80=AFAM Stefa=
n Traud <<a rel=3D"nofollow noopener noreferrer" shape=3D"rect" ymailto=
=3D"mailto:[email protected]" target=3D"_blank" href=3D"mailto:stefan_=
[email protected]">[email protected]</a>> wrote:<br clear=3D"none"></=
div><blockquote style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb=
(204,204,204);padding-left:1ex;" class=3D"yiv9798084774gmail_quote"><div><d=
iv style=3D"font-family: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 sup=
port (based on XML Stream API with moshi).</div><div dir=3D"ltr"><br clear=
=3D"none"></div><div dir=3D"ltr">I'm currently struggling with xml types th=
at include attributes. To reproduce the issue I have amended the wsdl in th=
e samples.quickstartadb to include an attribute in the getPrice element:</d=
iv><div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr"><div><div sty=
le=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;">=09=09=09<span style=3D"=
color:rgb(0,128,128);"><</span><span style=3D"color:rgb(63,127,127);">xs=
:element</span> <span style=3D"color:rgb(127,0,127);">name</span>=3D<span s=
tyle=3D"color:rgb(42,0,255);font-style:italic;">"getPrice"</span><span styl=
e=3D"color:rgb(0,128,128);">></span></p><p style=3D"margin:0px;">=09=09=
=09=09<span style=3D"color:rgb(0,128,128);"> <</s=
pan><span style=3D"color:rgb(63,127,127);">xs:complexType</span><span style=
=3D"color:rgb(0,128,128);">></span></p><p style=3D"margin:0px;">=09=09=
=09=09=09<span style=3D"color:rgb(0,128,128);"> &nbs=
p; <</span><span style=3D"color:rgb(63,127,127);">xs:se=
quence</span><span style=3D"color:rgb(0,128,128);">></span></p><div styl=
e=3D"margin:0px;"><span style=3D"color:rgb(0,128,128);"> &=
nbsp; <</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=
;">"symbol"</span> </div><div style=3D"margin:0px;"><span style=3D"col=
or:rgb(127,0,127);"> &=
nbsp; nillable</span>=3D<span style=3D"c=
olor:rgb(42,0,255);font-style:italic;">"true" </span><span style=3D"fo=
nt-size:10pt;color:rgb(127,0,127);">type</span><span style=3D"font-size:10p=
t;">=3D</span><span style=3D"font-size:10pt;color:rgb(42,0,255);font-style:=
italic;">"xs:string"</span><span style=3D"font-size:10pt;"> </span><span st=
yle=3D"font-size:10pt;color:rgb(0,128,128);">/></span></div><p style=3D"=
margin:0px;">=09=09=09=09=09<span style=3D"color:rgb(0,128,128);"> &nb=
sp; </</span><span style=3D"color:rgb=
(63,127,127);">xs:sequence</span><span style=3D"color:rgb(0,128,128);">>=
</span></p><div style=3D"margin:0px;"><span style=3D"color:rgb(0,128,128);"=
> <</span><span style=3D"=
color:rgb(63,127,127);">xs:attribute</span> <span style=3D"color:rgb(127,0,=
127);">name</span>=3D<span style=3D"color:rgb(42,0,255);font-style:italic;"=
>"currency"</span> </div><div style=3D"margin:0px;"><span style=3D"col=
or:rgb(127,0,127);"> &=
nbsp; type</span>=3D<span style=3D"color:rgb(42,0,255);font-styl=
e:italic;">"xs:string"</span> <span style=3D"color:rgb(127,0,127);">use</sp=
an>=3D<span style=3D"color:rgb(42,0,255);font-style:italic;">"required"</sp=
an><span style=3D"color:rgb(0,128,128);">/></span></div><p style=3D"marg=
in:0px;">=09=09=09=09<span style=3D"color:rgb(0,128,128);"> &nbs=
p; </</span><span style=3D"color:rgb(63,127,127);">xs:complexType</=
span><span style=3D"color:rgb(0,128,128);">></span></p><p style=3D"margi=
n:0px;">=09=09=09<span style=3D"color:rgb(0,128,128);"></</span><span st=
yle=3D"color:rgb(63,127,127);">xs:element</span><span style=3D"color:rgb(0,=
128,128);">></span></p></div></div></div><br clear=3D"none"></div><div d=
ir=3D"ltr">My corresponding JSON message should then be something like:</di=
v><div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr">{ "getPrice" :=
{"@currency": "USD", "symbol": "IBM" }}</div><div dir=3D"ltr"><br clear=3D=
"none"></div><div dir=3D"ltr">However the parse method in the GetPrice ADBB=
ean keeps complaining "<span><span style=3D"padding:0px 0px 0px 2px;"><span=
style=3D"color:rgb(0,0,0);font-family:Consolas;font-size:10pt;">Required a=
ttribute currency is missing</span></span></span>"; specifically this call =
returns null:</div><div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"lt=
r"><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);">"<a rel=3D"nofollow noopener noreferrer" shape=3D=
"rect" target=3D"_blank" href=3D"http://quickstart.samples/xsd">http://quic=
kstart.samples/xsd</a>"</span>, <span style=3D"color:rgb(42,0,255);">"curre=
ncy"</span>);</div><div style=3D"margin:0px;"><br clear=3D"none"></div></di=
v></div></div>(However it works when using SOAP).</div><div dir=3D"ltr"><br=
clear=3D"none"></div><div dir=3D"ltr">Do I need to define attributes diffe=
rently in the JSON message?</div><div dir=3D"ltr"><br clear=3D"none"></div>=
<div dir=3D"ltr"><br clear=3D"none"></div></div></div></blockquote></div>
</blockquote></div></div>
</div></div></div>
</div>
</div></body></html>
------=_Part_1891485_1918280389.1739955741036--