axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sagara Gunathunga <sagara.gunathu...@gmail.com>
Subject Re: [GSOC 2012] Improve Json support in Axis2 with google-gson, [Part-2]
Date Mon, 02 Jul 2012 10:14:43 GMT
On Sun, Jul 1, 2012 at 8:50 PM, Amila Suriarachchi
<amilasuriarachchi@gmail.com> wrote:
>
>
> On Fri, Jun 29, 2012 at 12:23 PM, Shameera Rathnayaka
> <shameerainfo@gmail.com> wrote:
>>
>> Hi devs,
>>
>> I have a problem with, writing OMElement to the wire
>> at the JsonFormatter, The problem is how do i identify
>> whether it is a JSON object or JSON array.
>>
>> As an example let's say i have this OMElement,
>>
>>     <student>
>>         <name>micky</name>
>>         <age>15</age>
>>         <subject>History</subject>
>>         <subject>Science</subject>
>>     </student>
>>
>> So the expected JSON Object is,
>> {"student":{"name":'micky" , "age":15 , "subject":["History", "Science"]}}
>>
>> The thing is how should I know the student should be a JsonArray, when i
>> receive a <subject> Start element?
>>
>> Another thing is if i get below OMElement, How do i know subject is a
>> JsonArray?
>>   <student>
>>         <name>micky</name>
>>         <age>15</age>
>>         <subject>History</subject>
>>     </student>
>>
>> The relevant JSON object should be,
>>
>> {"student":{"name":'micky" , "age":15 , "subject":["History"]}}
>>
>> It would be nice to hear your ideas to overcome these problems.
>
>
> It think we can not solve this issue unless the serialiser aware of some
> scheme. So this seems to be another limitation about converting xml to json
> and wise versa.
>
> Shall we follow this convention to over come this problem.
>
> if we take your example, shall we stick to a method where it always try to
> serialise fields as attributes unless we sure it is an array.
>
> For an example
>
> <student>
>         <name>micky</name>
>         <age>15</age>
>         <subject>History</subject>
>     </student>
>
> this will be
>
> {"student":{"name":'micky" , "age":15 , "subject":"History"}}
>
> and
>
> <student>
>         <name>micky</name>
>         <age>15</age>
>         <subject>History</subject>
>         <subject>Science</subject>
>     </student>
>
> {"student":{"name":'micky" , "age":15 , "subject":["History", "Science"]}}
>
> I think even implementation wise this will not be straight forward. The only
> thing we know for sure root element is not an array.
>
> Then after completing the first element, if the second element is also have
> the same element name then we can assume it is an array and other wise it is
> a normal attribute.

Amila,

Your suggestion introduce another problem, format of response JSON
message depends on return data quantities. As an example for a same
service it use two response formats when the response having size 1
array and having size > 1 arrays. I think this is a major issue for
caller side.

What about to use hybrid approach where XMLStramReader based approach
( 2nd approach)  use to handle incoming requests and use Gson stream
directly to write response message from Java ( Java => Gson)  without
using XMLStramWriter  (1st approach)    ?

Thanks !

>
> thanks,
> Amila.
>
>
>>
>>
>> Thanks,
>> Shameera.
>>
>>
>>
>>
>> On Mon, Jun 25, 2012 at 11:10 AM, Shameera Rathnayaka
>> <shameerainfo@gmail.com> wrote:
>>>
>>> Hi devs,
>>>
>>>> Everything is fine, if i try to print OMElement using
>>>> omElement.toString();
>>>> it prints OMElement without any error. But after returning from
>>>> JsonBuilder,
>>>> and inside the TransportUtils class it throws a class cast exception
>>>> when it try
>>>> to add this returned OMelement to the SoapEnvelop by using
>>>> envelope.getBody().addChild(documentElement); here is the code segment
>>>> in
>>>> TransportUtils class
>>>>
>>>> envelope = soapFactory.getDefaultEnvelope();
>>>> if (documentElement != null) {
>>>>      envelope.getBody().addChild(documentElement); // THIS LINE THROWS
>>>> AN EXCEPTION
>>>> }
>>>>
>>>> The exception is  java.lang.ClassCastException:
>>>> org.apache.axiom.om.impl.llom.OMDocumentImpl cannot be cast to
>>>> org.apache.axiom.om.impl.OMNodeEx
>>>
>>>
>>> I could able to solve this , there was an error in my GsonXMLStreamReader
>>> , I had to dig AXIOM to identify this. AXIOM process the parser while it
>>> receive XMLStreamReader.END_ELEMENT but my implementation had an error
>>> returning the END_ELEMENT, I solved it now I an not getting above
>>> ClassCastException.
>>>
>>> Thanks,
>>> Shameera.
>>>
>>>>
>>>>
>>>> What should be the problem for this? , do i use wrong way to get
>>>> the OMElement or something else??  devs any comments on this ??
>>>>
>>>> Thanks,
>>>> Shameera.
>>>>
>>>>
>>>> On Sat, May 5, 2012 at 11:30 AM, Shameera Rathnayaka
>>>> <shameerainfo@gmail.com> wrote:
>>>>>
>>>>> Hi devs ,
>>>>>
>>>>> According to my second approach, I need to map json elements in request
>>>>> to relevant XML tags/text and vice versa. When i am working on this,
there
>>>>> is a  problem arises that which convention should i expect for this.
So i
>>>>> need to clarify whether the following convention is correct or are there
any
>>>>> suggestions for it.
>>>>>
>>>>> json message
>>>>>
>>>>> {    "alise": {
>>>>>         "bob": {
>>>>>             "x": "valueX",
>>>>>             "y": "valueY",
>>>>>             "z": ["valueU","valueV","valueW"],
>>>>>             "l": { "name": "john",  "age": 23 },
>>>>>             "m": [ { "a": ["A","B","C" ]  }, { "b": ["D","E","F" ]  }
>>>>> ]
>>>>>         }
>>>>>     }
>>>>> }
>>>>>
>>>>> Relevant,expected xml message from this json request (actually, it is
>>>>> not converted to xml)
>>>>>
>>>>>     <json>
>>>>>         <alise>
>>>>>             <bob>
>>>>>                 <x>valueX</x>
>>>>>                 <y>valueY</y>
>>>>>                 <z>valueU</z>
>>>>>                 <z>valueV</z>
>>>>>                 <z>valueW</z>
>>>>>                 <l>
>>>>>                     <name>john</name>
>>>>>                     <age>23</age>
>>>>>                 </l>
>>>>>                 <m>
>>>>>                     <a>A</a>
>>>>>                     <a>B</a>
>>>>>                     <a>C</a>
>>>>>                 </m>
>>>>>                 <m>
>>>>>                     <b>D</b>
>>>>>                     <b>E</b>
>>>>>                     <b>F</b>
>>>>>                 </m>
>>>>>             </bob>
>>>>>         </alise>
>>>>>     </json>
>>>>>
>>>>>
>>>>> Thanks
>>>>> Shameera.
>>>>>
>>>>>
>>>>> On Tue, Apr 24, 2012 at 7:12 PM, Shameera Rathnayaka
>>>>> <shameerainfo@gmail.com> wrote:
>>>>>>
>>>>>> Hi devs,
>>>>>>
>>>>>> As this project is accepted for GSoC 2012, I would like
>>>>>> to continue my work and looking forward to finish my project
>>>>>> as a success in this summer. According to my mentor (Amila
>>>>>> Suriarachchi)
>>>>>> it is better to improve my knowledge further about Axis2 architecture
>>>>>> in this community bounding period. Therefore I'll start to read the
>>>>>> Documentation and Apache Axis2 book.
>>>>>>
>>>>>> Andreas, as you mentioned in the previous mail thread[1] could you
>>>>>> please point out some of the code samples in synapse which do
>>>>>> a similar work as i do in my 2nd approach of the project?.
>>>>>>
>>>>>> I will use this thread for future discussion about the project.
>>>>>> And I'll keep update my implementation patches to  AXIS2-5270 too.
>>>>>>
>>>>>>
>>>>>> [1]
>>>>>> http://axis.markmail.org/thread/4lg7xefplv7o65z6#query:page:1+mid:u7zauh37nj4mje6n+state:results
>>>>>>
>>>>>> Thanks
>>>>>> Shameera.
>>>>>>
>>>>>> --
>>>>>> Shameera Rathnayaka
>>>>>> Undergraduate
>>>>>> Department of Computer Science and Engineering
>>>>>> University of Moratuwa.
>>>>>> Sri Lanka.
>>>>>>
>>>>>> Blog : http://shameerarathnayaka.blogspot.com/
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Shameera Rathnayaka
>>>>> Undergraduate
>>>>> Department of Computer Science and Engineering
>>>>> University of Moratuwa.
>>>>> Sri Lanka.
>>>>>
>>>>> Blog : http://shameerarathnayaka.blogspot.com/
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Shameera Rathnayaka
>>>> Undergraduate
>>>> Department of Computer Science and Engineering
>>>> University of Moratuwa.
>>>> Sri Lanka.
>>>>
>>>> Blog : http://shameerarathnayaka.blogspot.com/
>>>>
>>>
>>>
>>>
>>>
>>> --
>>> Shameera Rathnayaka
>>> Undergraduate
>>> Department of Computer Science and Engineering
>>> University of Moratuwa.
>>> Sri Lanka.
>>>
>>> Blog : http://shameerarathnayaka.blogspot.com/
>>>
>>
>>
>>
>> --
>> Shameera Rathnayaka
>> Undergraduate
>> Department of Computer Science and Engineering
>> University of Moratuwa.
>> Sri Lanka.
>>
>> Blog : http://shameerarathnayaka.blogspot.com/
>>
>
>
>
> --
> Amila Suriarachchi
> WSO2 Inc.
> blog: http://amilachinthaka.blogspot.com/



-- 
Sagara Gunathunga

Blog      - http://ssagara.blogspot.com
Web      - http://people.apache.org/~sagara/
LinkedIn - http://www.linkedin.com/in/ssagara

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
For additional commands, e-mail: java-dev-help@axis.apache.org


Mime
View raw message