Re: JSON with XML Stream API/moshi

robertlazarski <[email protected]> Thu, 13 Mar 2025 05:14:55 -1000
Newsgroups gmane.text.xml.axis.user
Message-ID <CABpPLBUtHWcODRpAi83QkmR-Lon3xfYraYGBtYckjwARXQvyHw@mail.gmail.com>
--0000000000007f54ba06303ac947
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

No worries.

The code starting the XML Attribute support for XML Stream, as discussed in
this email thread, went out with Axis2 2.0.0 release this past Monday.

Axis2 is now jakarta based, so you will need the latest Tomcat or Wildfly
to run it.

If you need any help finishing this support, let me know. What needs to
happen now is someone with this use case and motivation to debug it until
it works.

I don't have this use case myself and am busy on other things at the
moment, but I am highly motivated on improving our overall JSON support and
will do what I can to see this feature get implemented.

On Thu, Mar 13, 2025 at 4:47=E2=80=AFAM Stefan Traud <[email protected]=
m> wrote:

> Thanks a lot for looking into this (and apologies for the late response) =
-
> very much appreciated!
>
>
> Am Donnerstag, 27. Februar 2025 um 16:38:40 MEZ hat robertlazarski <
> [email protected]> Folgendes geschrieben:
>
>
> Thanks for posting your config files, that helped me understand a bit mor=
e
> of what you are trying to do as I only use the "native" JSON approach wit=
h
> POJO's at my day job. I haven't looked much at the Stax support code usin=
g
> the XMLSchema project.
>
> And you were correct in pointing out the comments indicating that
> attributes are not supported.
>
> Anyways, I gave the coding to support attributes a shot but ran out of
> time after getting about 80% the way there - ideally someone with this us=
e
> case can complete the coding though our git repo code requires Tomcat 11 =
/
> Wildfly 32.
>
> See this commit. I created an attribute queue. If the JsonObject as an
> attribute would be added to the main queue, it would incorrectly end up a=
s
> an Element in the SOAP body generated from JSONHandler.
>
>
> https://github.com/apache/axis-axis2-java-core/commit/16e832e71ef809ddd85=
de386b43719575d0a7b7c
>
> I also created this Jira issue:
>
> https://issues.apache.org/jira/browse/AXIS2-6081
>
> What needs to happen is getAttributeCount() and getAttributeName() need t=
o
> call nextName() and nextValue()
> with some type of flag that tells the method to switch to the attribute
> queue.
>
> With the current code, it will consider JSON with a currency attribute
> added invalid because it doesn't read all of it since this Stax streaming
> approach needs that JsonObject in the attributes queue.
>
> On Sun, Feb 23, 2025 at 10:42=E2=80=AFPM Stefan Traud <stefan_traud@yahoo=
.com>
> wrote:
>
> I'm using the services.xml without modification as per
> samples.quickstartadb.resources.META-INF.services.xml. Please see attache=
d.
> Regarding the axis2.xml, I have modified according to the guidelines in A=
pache
> Axis2 =E2=80=93 How to configure Native approach and XML Stream API base =
approach
> <https://axis.apache.org/docs/json_gson_user_guide.html> for the XML
> Stream API based approach (and replacing occurences of "gson" with
> "moshi"). Please find attached.
>
> In the transport phase, I have added:
>
> <handler name=3D"RequestURIOperationDispatcher"
>
> class=3D"org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
>
> <handler name=3D"JSONMessageHandler"
> class=3D"org.apache.axis2.json.moshi.JSONMessageHandler" />
>
>
> However, I have not modified the RequestURIBasedDispatcher that was
> already there from the axis2-1.8.2 default axis2.xml as follows:
>
> <handler name=3D"RequestURIBasedDispatcher"
>
> class=3D"org.apache.axis2.dispatchers.RequestURIBasedDispatcher">
>
> <order phase=3D"Transport"/>
>
> </handler>
>
>
>
> Regarding the moshi.MoshiXMLStreamReader: While I can not see any of the
> unsupported methods being entered during debugging, I can see the
> getAttributeCount method being invoked. This method always returns 0.
>
> Am Montag, 24. Februar 2025 um 07:00:14 MEZ hat robertlazarski <
> [email protected]> Folgendes geschrieben:
>
>
> I was able to follow your examples with the currency attribute and get
> some results but it seems like you have some service.xml and axis2.xml
> configurations I am unsure about - could you please post them?
>
> With the service.xml and axis2.xml largely from the spring boot demo I
> conjured up with the current state of git master - the one difference is
> you are using RequestURIBasedDispatcher instead of the new class
> JSONBasedDefaultDispatcher
> which works, so I used that too - I am sending this:
>
> {"getPrice":[{"arg0":{"currency":USD,"symbol":IBM}}]}
>
> And getting this response:
>
> {"response":{"local_return":42.0}}
>
> The problem is the skeleton is receiving null values for the currency and
> symbol for some reason.
>
> About the MoshiXMLStreamReader question - I don't see that condition
> being entered during my debugging.
>
>
> On Fri, Feb 21, 2025 at 12:52=E2=80=AFAM Stefan Traud <stefan_traud@yahoo=
.com>
> wrote:
>
> In between I have also looked into the source of
> org.apache.axis2.json.moshi.MoshiXMLStreamReader and I find
>
> public int getAttributeCount() {
>
> if (isStartElement()) {
>
> return 0; *//* *don't support attributes on tags in JSON convention*
>
> } else {
>
> throw new IllegalStateException("Only valid on START_ELEMENT state");
>
> }
>
> }
>
>
> public QName getAttributeName(int index) {
>
> throw new UnsupportedOperationException("Method is not implemented");
> }
>
> Attributes get ignored (attribute count will be returned as 0). It appear=
s
> that I cannot use the current XML Stream API based approach togehter with
> ADB in my case, at least not without substantial changes in the used
> xml-schemas.
>
>
> Am Mittwoch, 19. Februar 2025 um 09:26:07 MEZ hat Stefan Traud <
> [email protected]> Folgendes geschrieben:
>
>
> I'm attaching 2 debug logs:
>
>    - soap.log: processing of the getPrice request using the ADBClient
>    from samples.quickstartadb (modified only to set the required currency
>    attribute using StockQuoteService.setCurrency). This returns the expec=
ted
>    result.
>    - json.log: processing of the getPrice request using a post of the
>    json message string {"getPrice":{"@currency":"USD","symbol":"IBM"}}
>    with content-type application/json and url
>    http://localhost:8080/axis2/services/StockQuoteService/getPrice. This
>    results in internal server error due to missing required attribute.
>
>
> For your reference, I'm also attaching the modified StockQuoteService.wsd=
l
> from the samples.quickstartadb (adding required attribute 'currency' to t=
he
> getPrice data type).
>
> I also played with various variations of the json message (using
> "currency" instead of "@currency", changing order, or using "_attributes"=
 :
> {"currency":"USD"}. This trial-and-error approach does not work.
>
> I also tried what happens if I change the wsdl to require an attribute in
> the getPriceResponse (instead of in the request), as this will use the mo=
shi.JsonFormatter
> to write the output JSON (I hoped to see what convention would be used by
> moshi when producing the json string). However the attribute is simply
> ignored and not included in the response json.
>
> Am Dienstag, 18. Februar 2025 um 16:38:57 MEZ hat robertlazarski <
> [email protected]> Folgendes geschrieben:
>
>
> 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 mosh=
i).
>
> 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 "Requi=
red
> 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?
>
>
>

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

<div dir=3D"ltr"><div>No worries. <br></div><div><br></div><div>The code st=
arting the XML Attribute support for XML Stream, as discussed in this email=
 thread, went out with Axis2 2.0.0 release this past Monday.=C2=A0</div><di=
v><br></div><div>Axis2 is now jakarta based, so you will need the latest To=
mcat or Wildfly to run it. <br></div><div><br></div><div>If you need any he=
lp finishing this support, let me know. What needs to happen now is someone=
 with this use case and motivation to debug it until it works.=C2=A0</div><=
div><br></div><div>I don&#39;t have this use case myself and am busy on oth=
er things at the moment, but I am highly motivated on improving our overall=
 JSON support and will do what I can to see this feature get implemented.=
=C2=A0=C2=A0 <br></div></div><br><div class=3D"gmail_quote gmail_quote_cont=
ainer"><div dir=3D"ltr" class=3D"gmail_attr">On Thu, Mar 13, 2025 at 4:47=
=E2=80=AFAM Stefan Traud &lt;<a href=3D"mailto:[email protected]">stef=
[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(204,204,204);=
padding-left:1ex"><div><div style=3D"font-family:Helvetica Neue,Helvetica,A=
rial,sans-serif;font-size:13px"><div></div>
        <div dir=3D"ltr">Thanks a lot for looking into this (and apologies =
for the late response) - very much appreciated!</div><div dir=3D"ltr"><br><=
/div><div><br></div>
       =20
        </div><div id=3D"m_-8907827309902428854yahoo_quoted_2431688091">
            <div style=3D"font-family:&quot;Helvetica Neue&quot;,Helvetica,=
Arial,sans-serif;font-size:13px;color:rgb(38,40,42)">
               =20
                <div>
                        Am Donnerstag, 27. Februar 2025 um 16:38:40 MEZ hat=
 robertlazarski &lt;<a href=3D"mailto:[email protected]" target=3D"_=
blank">[email protected]</a>&gt; Folgendes geschrieben:
                    </div>
                    <div><br></div>
                    <div><br></div>
               =20
               =20
                <div><div id=3D"m_-8907827309902428854yiv1914504297"><div><=
div dir=3D"ltr"><div>Thanks for posting your config files, that helped me u=
nderstand a bit more of what you are trying to do as I only use the &quot;n=
ative&quot; JSON approach with POJO&#39;s at my day job. I haven&#39;t look=
ed much at the Stax support code using the XMLSchema project.</div><div><br=
 clear=3D"none"></div><div>And you were correct in pointing out the comment=
s indicating that attributes are not supported. <br clear=3D"none"></div><d=
iv><br clear=3D"none"></div><div>Anyways, I gave the coding to support attr=
ibutes a shot but ran out of time after getting about 80% the way there - i=
deally someone with this use case can complete the coding though our git re=
po code requires Tomcat 11 / Wildfly 32. <br clear=3D"none"></div><div><br =
clear=3D"none"></div><div> See this commit. I created an attribute queue. I=
f the JsonObject as an attribute would be added to the main queue, it would=
 incorrectly end up as an Element in the SOAP body generated from JSONHandl=
er. <br clear=3D"none"></div><div><br clear=3D"none"></div><div><a rel=3D"n=
ofollow noopener noreferrer" shape=3D"rect" href=3D"https://github.com/apac=
he/axis-axis2-java-core/commit/16e832e71ef809ddd85de386b43719575d0a7b7c" ta=
rget=3D"_blank">https://github.com/apache/axis-axis2-java-core/commit/16e83=
2e71ef809ddd85de386b43719575d0a7b7c</a></div><div><br clear=3D"none"></div>=
<div>I also created this Jira issue:</div><div><br clear=3D"none"></div><di=
v><a rel=3D"nofollow noopener noreferrer" shape=3D"rect" href=3D"https://is=
sues.apache.org/jira/browse/AXIS2-6081" target=3D"_blank">https://issues.ap=
ache.org/jira/browse/AXIS2-6081</a></div><div><br clear=3D"none"></div><div=
>What needs to happen is getAttributeCount() and getAttributeName() need to=
 call nextName() and <span style=3D"font-family:monospace"><span style=3D"c=
olor:rgb(0,0,0);background-color:rgb(255,255,255)">nextValue()</span><br cl=
ear=3D"none"></span>with some type of flag that tells the method to switch =
to the attribute queue.=C2=A0 <br clear=3D"none"></div><div><br clear=3D"no=
ne"></div><div>With the current code, it will consider JSON with a currency=
 attribute added invalid because it doesn&#39;t read all of it since this S=
tax streaming approach needs that JsonObject in the attributes queue. <br c=
lear=3D"none"></div></div><br clear=3D"none"><div id=3D"m_-8907827309902428=
854yiv1914504297yqt42280"><div><div dir=3D"ltr">On Sun, Feb 23, 2025 at 10:=
42=E2=80=AFPM Stefan Traud &lt;<a rel=3D"nofollow noopener noreferrer" shap=
e=3D"rect" href=3D"mailto:[email protected]" target=3D"_blank">stefan_=
[email protected]</a>&gt; wrote:<br clear=3D"none"></div><blockquote style=3D=
"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-le=
ft:1ex"><div><div style=3D"font-family:Helvetica Neue,Helvetica,Arial,sans-=
serif;font-size:13px"><div></div>
        <div dir=3D"ltr">I&#39;m using the services.xml without modificatio=
n as per samples.quickstartadb.resources.META-INF.services.xml. Please see =
attached. Regarding the axis2.xml, I have modified according to the guideli=
nes in=C2=A0<span><a rel=3D"nofollow noopener noreferrer" shape=3D"rect" hr=
ef=3D"https://axis.apache.org/docs/json_gson_user_guide.html" target=3D"_bl=
ank">Apache Axis2 =E2=80=93 How to configure Native approach and XML Stream=
 API base approach</a>=C2=A0for the XML Stream API based approach (and repl=
acing occurences of &quot;gson&quot; with &quot;moshi&quot;). Please find a=
ttached.</span></div><div dir=3D"ltr"><span><br clear=3D"none"></span></div=
><div dir=3D"ltr"><span>In the transport phase, I have added:</span></div><=
div dir=3D"ltr"><span><br clear=3D"none"></span></div><div dir=3D"ltr"><div=
 style=3D"padding:0px 0px 0px 2px"><div style=3D"color:rgb(0,0,0);font-fami=
ly:Consolas;font-size:10pt"><p style=3D"margin:0px"><span style=3D"color:rg=
b(0,128,128)">&lt;</span><span style=3D"color:rgb(63,127,127)">handler</spa=
n> <span style=3D"color:rgb(127,0,127)">name</span>=3D<span style=3D"color:=
rgb(42,0,255);font-style:italic">&quot;RequestURIOperationDispatcher&quot;<=
/span></p><p style=3D"margin:0px">                             <span style=
=3D"color:rgb(127,0,127)">class</span>=3D<span style=3D"color:rgb(42,0,255)=
;font-style:italic">&quot;org.apache.axis2.dispatchers.RequestURIOperationD=
ispatcher&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)">&l=
t;</span><span style=3D"color:rgb(63,127,127)">handler</span> <span style=
=3D"color:rgb(127,0,127)">name</span>=3D<span style=3D"color:rgb(42,0,255);=
font-style:italic">&quot;JSONMessageHandler&quot;</span></p><div style=3D"m=
argin:0px"><span style=3D"color:rgb(127,0,127)">class</span>=3D<span style=
=3D"color:rgb(42,0,255);font-style:italic">&quot;org.apache.axis2.json.mosh=
i.JSONMessageHandler&quot;</span> <span style=3D"color:rgb(0,128,128)">/&gt=
;</span></div></div></div></div><div dir=3D"ltr"><br clear=3D"none"></div><=
div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr">However, I have n=
ot modified the <span style=3D"padding:0px 0px 0px 2px"><span style=3D"font=
-family:Consolas;font-size:10pt"><span style=3D"color:rgb(42,0,255);font-st=
yle:italic">RequestURIBasedDispatcher </span></span></span>that was already=
 there from the axis2-1.8.2 default axis2.xml as follows:</div><div dir=3D"=
ltr"><span><br clear=3D"none"></span></div><div dir=3D"ltr"><div style=3D"p=
adding:0px 0px 0px 2px"><div style=3D"color:rgb(0,0,0);font-family:Consolas=
;font-size:10pt"><p dir=3D"ltr" style=3D"margin:0px"> </p><div><div style=
=3D"padding:0px 0px 0px 2px"><div style=3D"color:rgb(0,0,0);font-family:Con=
solas;font-size:10pt"><p style=3D"margin:0px"><span style=3D"color:rgb(0,12=
8,128)">&lt;</span><span style=3D"color:rgb(63,127,127);background-color:rg=
b(212,212,212)">handler</span> <span style=3D"color:rgb(127,0,127)">name</s=
pan>=3D<span style=3D"color:rgb(42,0,255);font-style:italic">&quot;RequestU=
RIBasedDispatcher&quot;</span></p><p style=3D"margin:0px">                 =
    <span style=3D"color:rgb(127,0,127)">class</span>=3D<span style=3D"colo=
r:rgb(42,0,255);font-style:italic">&quot;org.apache.axis2.dispatchers.Reque=
stURIBasedDispatcher&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)">&lt;</span><span style=3D"color:rgb(63,127,127)">order</span> <=
span style=3D"color:rgb(127,0,127)">phase</span>=3D<span style=3D"color:rgb=
(42,0,255);font-style:italic">&quot;Transport&quot;</span><span style=3D"co=
lor:rgb(0,128,128)">/&gt;</span></p><p style=3D"margin:0px">            <sp=
an style=3D"color:rgb(0,128,128)">&lt;/</span><span style=3D"color:rgb(63,1=
27,127);background-color:rgb(212,212,212)">handler</span><span style=3D"col=
or:rgb(0,128,128)">&gt;</span></p></div></div></div><p></p><div style=3D"ma=
rgin:0px"><br clear=3D"none"></div></div></div></div><div dir=3D"ltr"><br c=
lear=3D"none"></div><div dir=3D"ltr"><span>Regarding the moshi.MoshiXMLStre=
amReader: While I can not see any of the unsupported methods being entered =
during debugging, I can see the getAttributeCount method being invoked. Thi=
s method always returns 0.=C2=A0</span></div><div><br clear=3D"none"></div>
       =20
        </div><div id=3D"m_-8907827309902428854yiv1914504297m_-645181426719=
2055376m_3835683055986474251yahoo_quoted_1177848542">
            <div style=3D"font-family:Helvetica,Arial,sans-serif;font-size:=
13px;color:rgb(38,40,42)">
               =20
                <div>
                        Am Montag, 24. Februar 2025 um 07:00:14 MEZ hat rob=
ertlazarski &lt;<a rel=3D"nofollow noopener noreferrer" shape=3D"rect" href=
=3D"mailto:[email protected]" target=3D"_blank">robertlazarski@gmail=
.com</a>&gt; Folgendes geschrieben:
                    </div>
                    <div><br clear=3D"none"></div>
                    <div><br clear=3D"none"></div>
               =20
               =20
                <div><div id=3D"m_-8907827309902428854yiv1914504297m_-64518=
14267192055376m_3835683055986474251yiv2506349534"><div><div dir=3D"ltr"><di=
v>I was able to follow your examples with the currency attribute and get so=
me results but it seems like you have some service.xml and axis2.xml config=
urations I am unsure about - could you please post them? <br clear=3D"none"=
></div><div><br clear=3D"none"></div><div>With the service.xml and axis2.xm=
l largely from the spring boot demo I conjured up with the current state of=
 git master - the one difference is you are using=C2=A0<span style=3D"font-=
family:monospace"><span style=3D"color:rgb(0,0,0);background-color:rgb(255,=
255,255)">RequestURIBasedDispatcher</span></span> instead of the new class =
<span style=3D"font-family:monospace"><span style=3D"color:rgb(0,0,0);backg=
round-color:rgb(255,255,255)">JSONBasedDefaultDispatcher</span><br clear=3D=
"none"></span>which works, so I used that too - I am sending this: <br clea=
r=3D"none"></div><div><br clear=3D"none"></div><div><span style=3D"font-fam=
ily:monospace"><span style=3D"color:rgb(0,0,0);background-color:rgb(255,255=
,255)">{&quot;getPrice&quot;:[{&quot;arg0&quot;:{&quot;currency&quot;:USD,&=
quot;symbol&quot;:IBM}}]}</span><br clear=3D"none"></span></div><div><span =
style=3D"font-family:monospace"><br clear=3D"none"></span></div><div><span =
style=3D"font-family:monospace">And getting this response: <br clear=3D"non=
e"></span></div><div><span style=3D"font-family:monospace"><br clear=3D"non=
e"></span></div><div><span style=3D"font-family:monospace"><span style=3D"c=
olor:rgb(0,0,0);background-color:rgb(255,255,255)">{&quot;response&quot;:{&=
quot;local_return&quot;:42.0}}</span><br clear=3D"none"></span></div><div><=
span style=3D"font-family:monospace"><br clear=3D"none"></span></div><div><=
span style=3D"font-family:monospace">The problem is the skeleton is receivi=
ng null values for the currency and symbol for some reason. <br clear=3D"no=
ne"></span></div><div><br clear=3D"none"></div><div>About the <span style=
=3D"font-family:monospace"><span style=3D"color:rgb(0,0,0);background-color=
:rgb(255,255,255)">MoshiXMLStreamReader question - I don&#39;t see that con=
dition being entered during my debugging. </span><br clear=3D"none"></span>=
<br clear=3D"none"></div></div><br clear=3D"none"><div id=3D"m_-89078273099=
02428854yiv1914504297m_-6451814267192055376m_3835683055986474251yiv25063495=
34yqt77091"><div><div dir=3D"ltr">On Fri, Feb 21, 2025 at 12:52=E2=80=AFAM =
Stefan Traud &lt;<a rel=3D"nofollow noopener noreferrer" shape=3D"rect" hre=
f=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
m</a>&gt; wrote:<br clear=3D"none"></div><blockquote style=3D"margin:0px 0p=
x 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><=
div style=3D"font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-siz=
e:13px"><div></div>
        <div dir=3D"ltr">In between I have also looked into the source of o=
rg.apache.axis2.json.moshi.MoshiXMLStreamReader and I find</div><div dir=3D=
"ltr"><br clear=3D"none"></div><div dir=3D"ltr"><div><div style=3D"padding:=
0px 0px 0px 2px"><div style=3D"font-family:Consolas;font-size:10pt"><p styl=
e=3D"color:rgb(0,0,0);margin:0px"><span style=3D"color:rgb(127,0,85);font-w=
eight:bold">public</span> <span style=3D"color:rgb(127,0,85);font-weight:bo=
ld">int</span> getAttributeCount() {</p><p style=3D"color:rgb(0,0,0);margin=
:0px">        <span style=3D"color:rgb(127,0,85);font-weight:bold">if</span=
> (isStartElement()) {</p><p style=3D"margin:0px">            <span style=
=3D"color:rgb(127,0,85);font-weight:bold">return</span> 0; <font color=3D"#=
cd232c"><b>//</b></font><span style=3D"color:rgb(63,127,95)"> </span><font =
color=3D"#cd232c"><b>don&#39;t support attributes on tags  in JSON conventi=
on</b></font></p><p style=3D"color:rgb(0,0,0);margin:0px">        } <span s=
tyle=3D"color:rgb(127,0,85);font-weight:bold">else</span> {</p><p style=3D"=
color:rgb(0,0,0);margin:0px">            <span style=3D"color:rgb(127,0,85)=
;font-weight:bold">throw</span> <span style=3D"color:rgb(127,0,85);font-wei=
ght:bold">new</span> IllegalStateException(<span style=3D"color:rgb(42,0,25=
5)">&quot;Only valid on START_ELEMENT state&quot;</span>);</p><p style=3D"c=
olor:rgb(0,0,0);margin:0px">        }</p><p style=3D"color:rgb(0,0,0);margi=
n:0px">    }</p><p style=3D"color:rgb(0,0,0);margin:0px"><br clear=3D"none"=
></p><p style=3D"color:rgb(0,0,0);margin:0px">    <span style=3D"color:rgb(=
127,0,85);font-weight:bold">public</span> QName getAttributeName(<span styl=
e=3D"color:rgb(127,0,85);font-weight:bold">int</span> <span style=3D"color:=
rgb(106,62,62)">index</span>) {</p><p style=3D"color:rgb(0,0,0);margin:0px"=
>        <span style=3D"color:rgb(127,0,85);font-weight:bold">throw</span> =
<span style=3D"color:rgb(127,0,85);font-weight:bold">new</span> Unsupported=
OperationException(<span style=3D"color:rgb(42,0,255)">&quot;Method is not =
implemented&quot;</span>);</p><div style=3D"color:rgb(0,0,0);margin:0px">  =
  }</div><div style=3D"color:rgb(0,0,0);margin:0px"><br clear=3D"none"></di=
v><div dir=3D"ltr" style=3D"color:rgb(0,0,0);margin:0px">Attributes get ign=
ored (attribute count will be returned as 0). It appears that I cannot use =
the current XML Stream API based approach togehter with ADB in my case, at =
least not without substantial changes in the used xml-schemas.</div></div><=
/div></div><br clear=3D"none"></div><div><br clear=3D"none"></div>
       =20
        </div><div id=3D"m_-8907827309902428854yiv1914504297m_-645181426719=
2055376m_3835683055986474251yiv2506349534m_-1352858088099866023yahoo_quoted=
_0984148450">
            <div style=3D"font-family:Helvetica,Arial,sans-serif;font-size:=
13px;color:rgb(38,40,42)">
               =20
                <div>
                        Am Mittwoch, 19. Februar 2025 um 09:26:07 MEZ hat S=
tefan Traud &lt;<a rel=3D"nofollow noopener noreferrer" shape=3D"rect" href=
=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
</a>&gt; Folgendes geschrieben:
                    </div>
                    <div><br clear=3D"none"></div>
                    <div><br clear=3D"none"></div>
               =20
               =20
                <div><div id=3D"m_-8907827309902428854yiv1914504297m_-64518=
14267192055376m_3835683055986474251yiv2506349534m_-1352858088099866023yiv99=
55715974"><div><div style=3D"font-family:Helvetica Neue,Helvetica,Arial,san=
s-serif;font-size:13px"><div></div>
        <div dir=3D"ltr">I&#39;m attaching 2 debug logs:</div><div dir=3D"l=
tr"><ul dir=3D"ltr"><li>soap.log: processing of the getPrice request using =
the ADBClient from samples.quickstartadb (modified only to set the required=
 currency attribute using StockQuoteService.setCurrency). This returns the =
expected result.</li><li>json.log: processing of the getPrice request using=
 a post of the json message string=C2=A0<span>{&quot;getPrice&quot;:{&quot;=
@currency&quot;:&quot;USD&quot;,&quot;symbol&quot;:&quot;IBM&quot;}} with c=
ontent-type application/json and url=C2=A0</span><a rel=3D"nofollow noopene=
r noreferrer" shape=3D"rect" href=3D"http://localhost:8080/axis2/services/S=
tockQuoteService/getPrice." target=3D"_blank">http://localhost:8080/axis2/s=
ervices/StockQuoteService/getPrice.</a>=C2=A0This results in internal serve=
r error due to missing required attribute.</li></ul><div><br clear=3D"none"=
></div><div dir=3D"ltr">For your reference, I&#39;m also attaching the modi=
fied StockQuoteService.wsdl from the samples.quickstartadb (adding required=
 attribute &#39;currency&#39; to the getPrice data type).</div><div dir=3D"=
ltr"><br clear=3D"none"></div><div dir=3D"ltr">I also played with various v=
ariations of the json message (using &quot;currency&quot; instead of &quot;=
@currency&quot;, changing order, or using &quot;_attributes&quot; : {&quot;=
currency&quot;:&quot;USD&quot;}. This trial-and-error approach does not wor=
k.</div><div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr">I also t=
ried what happens if I change the wsdl to require an attribute in the getPr=
iceResponse (instead of in the request), as this will use the=C2=A0<span>mo=
shi.JsonFormatter to write the output JSON (I hoped to see what convention =
would be used by moshi when producing the json string). However the attribu=
te is simply ignored and not included in the response json.</span></div></d=
iv><div><br clear=3D"none"></div>
       =20
        </div><div id=3D"m_-8907827309902428854yiv1914504297m_-645181426719=
2055376m_3835683055986474251yiv2506349534m_-1352858088099866023yiv995571597=
4yahoo_quoted_0201809127">
            <div style=3D"font-family:Helvetica,Arial,sans-serif;font-size:=
13px;color:rgb(38,40,42)">
               =20
                <div>
                        Am Dienstag, 18. Februar 2025 um 16:38:57 MEZ hat r=
obertlazarski &lt;<a rel=3D"nofollow noopener noreferrer" shape=3D"rect" hr=
ef=3D"mailto:[email protected]" target=3D"_blank">robertlazarski@gma=
il.com</a>&gt; Folgendes geschrieben:
                    </div>
                    <div><br clear=3D"none"></div>
                    <div><br clear=3D"none"></div>
               =20
               =20
                <div id=3D"m_-8907827309902428854yiv1914504297m_-6451814267=
192055376m_3835683055986474251yiv2506349534m_-1352858088099866023yiv9955715=
974yqt48543"><div><div id=3D"m_-8907827309902428854yiv1914504297m_-64518142=
67192055376m_3835683055986474251yiv2506349534m_-1352858088099866023yiv99557=
15974"><div><div dir=3D"ltr">Could you please paste or attach your logs? Th=
at may help me understand the problem better. I don&#39;t have use cases co=
mbining XML and JSON in my own projects but I know the code pretty well and=
 I can probably help. <br clear=3D"none"></div><br clear=3D"none"><div id=
=3D"m_-8907827309902428854yiv1914504297m_-6451814267192055376m_383568305598=
6474251yiv2506349534m_-1352858088099866023yiv9955715974yqt01052"><div><div =
dir=3D"ltr">On Mon, Feb 17, 2025 at 5:23=E2=80=AFAM Stefan Traud &lt;<a rel=
=3D"nofollow noopener noreferrer" shape=3D"rect" href=3D"mailto:stefan_trau=
[email protected]" target=3D"_blank">[email protected]</a>&gt; wrote:<br cle=
ar=3D"none"></div><blockquote style=3D"margin:0px 0px 0px 0.8ex;border-left=
:1px solid rgb(204,204,204);padding-left:1ex"><div><div style=3D"font-famil=
y:Helvetica Neue,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 clear=3D"none"><=
/div><div dir=3D"ltr">I&#39;m currently struggling with xml types that incl=
ude attributes. To reproduce the issue I have amended the wsdl in the sampl=
es.quickstartadb to include an attribute in the getPrice element:</div><div=
 dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr"><div><div style=3D"p=
adding: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> <s=
pan style=3D"color:rgb(127,0,127)">name</span>=3D<span style=3D"color:rgb(4=
2,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"col=
or: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,1=
28,128)">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0&lt;</span><span s=
tyle=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:rg=
b(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</sp=
an> <span style=3D"color:rgb(127,0,127)">name</span>=3D<span style=3D"color=
:rgb(42,0,255);font-style:italic">&quot;symbol&quot;</span>=C2=A0</div><div=
 style=3D"margin:0px"><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=A0=C2=A0=C2=A0=C2=A0=
=C2=A0nillable</span>=3D<span style=3D"color:rgb(42,0,255);font-style:itali=
c">&quot;true&quot;=C2=A0</span><span style=3D"font-size:10pt;color:rgb(127=
,0,127)">type</span><span 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:10p=
t;color:rgb(0,128,128)">/&gt;</span></div><p style=3D"margin:0px">					<spa=
n 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&lt;</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"col=
or:rgb(42,0,255);font-style:italic">&quot;currency&quot;</span>=C2=A0</div>=
<div style=3D"margin:0px"><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:rgb(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"col=
or:rgb(42,0,255);font-style:italic">&quot;required&quot;</span><span style=
=3D"color:rgb(0,128,128)">/&gt;</span></div><p style=3D"margin:0px">				<sp=
an 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"co=
lor:rgb(0,128,128)">&lt;/</span><span style=3D"color:rgb(63,127,127)">xs:el=
ement</span><span style=3D"color:rgb(0,128,128)">&gt;</span></p></div></div=
></div><br clear=3D"none"></div><div dir=3D"ltr">My corresponding JSON mess=
age should then be something like:</div><div dir=3D"ltr"><br clear=3D"none"=
></div><div dir=3D"ltr">{ &quot;getPrice&quot; : {&quot;@currency&quot;: &q=
uot;USD&quot;, &quot;symbol&quot;: &quot;IBM&quot; }}</div><div dir=3D"ltr"=
><br clear=3D"none"></div><div dir=3D"ltr">However the parse method in the =
GetPrice ADBBean keeps complaining &quot;<span><span style=3D"padding:0px 0=
px 0px 2px"><span style=3D"color:rgb(0,0,0);font-family:Consolas;font-size:=
10pt">Required attribute currency is missing</span></span></span>&quot;; sp=
ecifically this call returns null:</div><div dir=3D"ltr"><br clear=3D"none"=
></div><div dir=3D"ltr"><div><div style=3D"padding:0px 0px 0px 2px"><div st=
yle=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>.getAttribute=
Value(<span style=3D"color:rgb(42,0,255)">&quot;<a rel=3D"nofollow noopener=
 noreferrer" shape=3D"rect" href=3D"http://quickstart.samples/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"margi=
n:0px"><br clear=3D"none"></div></div></div></div>(However it works when us=
ing SOAP).</div><div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr">=
Do I need to define attributes differently in the JSON message?</div><div d=
ir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr"><br clear=3D"none"></d=
iv></div></div></blockquote></div></div>
</div></div></div></div>
            </div>
        </div></div></div></div>
            </div>
        </div></div></blockquote></div></div>
</div></div></div>
            </div>
        </div></div></blockquote></div></div>
</div></div></div>
            </div>
        </div></div></blockquote></div>

--0000000000007f54ba06303ac947--