Hi, that's because the default json provider is the org.apache.cxf.jaxrs.provider.json.JSONProvider with the option serializeAsArray to true (the opposite can lead to issues too).
the solution is to not rely on default providers and to configure your provider (even for json). You can add it as class in your application or configure it in openejb-jar.xml *Romain Manni-Bucau* *Twitter: @rmannibucau <https://twitter.com/rmannibucau>* *Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau* *Github: https://github.com/rmannibucau* 2012/10/29 kcundick <[email protected]> > Hi All, > > I believe I have run into a bug in the way that TomEE 1.5+ is handling JSON > when calling a RESTful service. > > I have a RESTful service called "UserService". The class is setup as > follows... > > @Path("/rest/userService") > @Produces({"application/json", "text/xml"}) > public class UserService { > ... > > Inside the class I have the following method... > > @Path("/getUserInfo") > @POST > public UserInfo getUserInfo(@FormParam("userId") @DefaultValue("0") final > String userId, > ... > > The getUserInfo method pulls information from the database using JPA and > returns it via the 'UserInfo' DTO. > > Everything works great. The data pulls fine and is correctly inside the > 'UserInfo' entity bean. Notice that I have not set this up to return a > List > of UserInfo, but just the UserInfo by itself. > > On the client side when the information is returned, since I upgraded to > TomEE 1.5, the JSON looks like this... > > {"userInfo":[{"email":"[email protected] > ","firstName":"Jon","langCode":"en","lastName":"Doe","id":7}]} > > It is returning the 'UserInfo' with an array, which is incorrect. It > should > look like this... > > {"loginMemberInfo":{"email":"[email protected] > ","firstName":"Jon","langCode":"en","lastName":"Doe","id":7}} > > The DTO declartion is as follows... > > @XmlRootElement > public class UserInfo implements Serializable { > ... > > Because we have a lot of code that utilizes RESTful in a similar fashion, > this potential bug is obviously causing us big problems. We will have to go > back and change a lot of code if this isn't fixed. > > We have tried using a different jettison library, an older one from TomEE > 1.0 but that didn't make any difference. > > Could someone confirm if this is a bug or if I'm just messing something up > some where? > > Thanks for your time! > > Kevin > > > > -- > View this message in context: > http://openejb.979440.n4.nabble.com/Possible-JSON-bug-in-TomEE-1-5-and-1-5-1-tp4658328.html > Sent from the OpenEJB User mailing list archive at Nabble.com. >
