Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » GF4+MOXy+@XmlNamedObjectGraph to generate JSON
GF4+MOXy+@XmlNamedObjectGraph to generate JSON [message #1235052] Thu, 23 January 2014 12:54 Go to next message
Neikius Mising name is currently offline Neikius Mising nameFriend
Messages: 43
Registered: April 2011
Member
So I am trying to do something like we used to do on GF3.1 using jackson+jersey @JsonView annotations.

Since GF4 is using MOXy by default I have decided to try it out.

@XmlNamedObjectGraph really seems to be doing what I want it to. The problem is I have to manually marshall to use the feature... my @WebMethod's are annotated with @Produces("application/json") and are returning List<Object> or Object types. Best (fastest and also the nicest code) to just annotate the @WebMethod somehow to tell it which Object graph to use.

Otherwise I guess I will have to study how the things are running in the backend to plug into serialization/marshalling process.

Any pointers on how to do this either way would be most welcome.
Re: GF4+MOXy+@XmlNamedObjectGraph to generate JSON [message #1235137 is a reply to message #1235052] Thu, 23 January 2014 16:41 Go to previous messageGo to next message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

Hi Neikius,

I would recommend asking this question on the Jersey mailing list (see: https://jersey.java.net/mailing.html). Michal Gajdos from Jersey has been thinking about this a lot and he presented some good information with me at JavaOne 2013. Check out the "Entity Filtering" section from our slides (linked below):

https://oracleus.activeevents.com/2013/connect/fileDownload/session/CC099DE9C02B34C23F9AF5236444B3F6/BOF5519_DoughanGajdos.pdf

-Blaise
Re: GF4+MOXy+@XmlNamedObjectGraph to generate JSON [message #1236458 is a reply to message #1235137] Mon, 27 January 2014 09:03 Go to previous message
Neikius Mising name is currently offline Neikius Mising nameFriend
Messages: 43
Registered: April 2011
Member
Thanks, asking it on the mailing list probably won't be necessary, the slides gave me what I needed, though I had some hard time even when I knew exactly what I was trying to do, also upgrading GF was a nightmare...

I am using @EntityFiltering annotations now as per Jersey 2.5 manual chapter 17, it works but you have to be really careful when using them. Without your slides I would have never figured out this feature existed.

Thanks again and I might drop by the mailing lists if I have more trouble regarding this.

Not really important but vaguely related problem:
Right now I have a strange problem regarding @XmlDiscriminator, moxy will force the default discriminator on me even though I don't ever unmarshall so I don't need it! Any way to disable that feature? I think I get the "type":"classname" discriminator property in JSON because I have a superclass, but if I remove the empty superclass I use on every entity right now, I get NPE again in createObjectGraph->createSubgraphs same as I got when I had cyclical bidirectional relations.

edit: Addendum-
This seems a MOXy "bug" - when creating an object graph it will always create the entire object graph, even when using entity filtering. This seems a) excessive b) problematic c) undesirable. @XmlTransient is ignored in this case. @XmlInverseReference seems to work but is a bit redundant when you are using @EntityFiltering annotations. Hence I won't be able to annotate my JPA entity model from db, but will be forced to copy field-by-field to a second set of @Xml annotated POJO's. I will probably just ditch everything from 2 days ago to today since it seems this brings more and more problems with zero benefits as I delve deeper.

[Updated on: Mon, 27 January 2014 10:03]

Report message to a moderator

Previous Topic:Accessing foreign key on @ManyToOne - how to avoid DB roundtrip?
Next Topic:Dynamic Moxy Exception for createContextFromXSD
Goto Forum:
  


Current Time: Thu Dec 18 23:50:07 GMT 2014

Powered by FUDForum. Page generated in 0.49739 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software