GF4+MOXy+@XmlNamedObjectGraph to generate JSON [message #1235052] |
Thu, 23 January 2014 12:54  |
Eclipse User |
|
|
|
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 #1236458 is a reply to message #1235137] |
Mon, 27 January 2014 09:03  |
Eclipse User |
|
|
|
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] by Moderator Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03221 seconds