Hi

You can possibly overcome this issue in the JAX-RS implementation by writing a custom JAXB context resolver which is supported in 0.7 JAX-RS API.

Please look at [1] for details.

[1] http://blogs.sun.com/japod/entry/missing_brackets_at_json_one

Yes, it's supported in CXF now too...If creating a custom 
jaxbContext/marshaller can fix this issue then another
option is to provide a custom JAXB ObjectFactory which will do the same what the custom JAX-RS ContextResolver implementation would do in this case...

Also, there's always an option to override a default (JSON) provider, for ex, by relying upon some alternative java json implementations...

Cheers, Sergey


-Arul

Daniel Kulp wrote:

I THINK this is an artifact of how jettison works. You might want to ask on the jettison list though. Basically, if jettison sees two elements of the same name in a row, it's an array, otherwise, it's a single value.

Dan



On Jul 18, 2008, at 3:14 PM, Joe Sunday wrote:

Is there a way to make this do the right thing?

If I have a schema like this:
   <xs:element name="A">
       <xs:complexType>
           <xs:sequence>
               <xs:element name="Foo" type="xs:string" minOccurs="1" 
maxOccurs="1"/>
               <xs:element name="Bar" type="xs:string" minOccurs="1" 
maxOccurs="1"/>
           </xs:sequence>
       </xs:complexType>
   </xs:element>

   <xs:element name="ArrayOfA">
       <xs:complexType>
           <xs:sequence>
               <xs:element ref="A" minOccurs="0" maxOccurs="unbounded"/>
           </xs:sequence>
       </xs:complexType>
   </xs:element>

and a REST method returning an ArrayOfA, I get structurally different results depending on if there's one A or more than one A in the result:
$ curl http://localhost:2259/myService/single
{"s.ArrayOfA":{"s.A":{"s.Foo":"foo","s.Bar":"bar"}}}

$ curl http://localhost:2259/myService/multiple
{"s.ArrayOfA":{"s.A":[{"s.Foo":"foo1","s.Bar":"bar1"},{"s.Foo":"foo2","s.Bar":"bar2"}]}}

In the first case, I get a Javascript object 'A' that has Foo and Bar directly on it. In the latter, that same object is the array I was expecting. So everywhere I get an object like this back from my service, I have to explicitly check if it's the first or second case and handle it slightly differently, rather than just iterating over A even if it's an array with one element.

--Joe


---
Daniel Kulp
[EMAIL PROTECTED]
http://www.dankulp.com/blog





________________________________
Scanned by MessageLabs for Flux
________________________________

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Reply via email to