A month ago I attended the Govhack (http://www.govhack.org/) event which was run around Australia to see what could be done with Government data in a weekend.
This was quite a bit of fun although I only had a day available to work on it the team had a cool idea for planning a trip using the Australia tourism data. We called it travelhackz and the summary is available at http://hackerspace.govhack.org/?q=groups/travelhackz
Big thanks to the rest of the team for their efforts on this!
Saturday, June 29, 2013
Lamdba Jam 2013 (Brisbane)
A month ago I went to the YOW Lambda Jam conference in brisbane - http://www.yowconference.com.au/lambdajam/. This was quite a bit of fun and had plenty of interesting talks.
One thing that I do plan on looking up is the iteratee pattern in the play framework (http://www.playframework.com/documentation/2.0/Iteratees). This was presented by Nilanjan Raychaudhuri and looks very interesting, I plan on having a look at this sometime soon.
One thing that I do plan on looking up is the iteratee pattern in the play framework (http://www.playframework.com/documentation/2.0/Iteratees). This was presented by Nilanjan Raychaudhuri and looks very interesting, I plan on having a look at this sometime soon.
Hack and Heckle
Recently I joined Darren and Leigh in their Hack and Heckle podcast (http://hackandheckle.com/). We talk about technology and the news that we've seen in the week as well as the local meetups and whatever side projects we happen to be working on.
This has been quite a bit of fun so tune in if you are interested.
This has been quite a bit of fun so tune in if you are interested.
Wednesday, June 5, 2013
Jersey, JAXB and json with generics and inheritance
A month or two ago I ran into an issue where I was marshalling Objects to json using Jersey with JAXB annotations on my pojos but only the Super Class attributes were being marshalled. I have uploaded some code to github to demonstrate this:
https://github.com/nebnagrom/jaxbInheritance
In this contrived example we have a Super Class House which has a member variable which is a String and an @XmlRootElement annotation. There are three child Classes of House:
The issue occured once I started trying to return HousingEstate objects from my RESTful resource. When you invoked the resource you only got back member variables from the House class, i.e. something like this:
{"houses":[{"houseName":"first blue"},{"houseName":"2 blue"}]}
When what I wanted was more like:
@XmlSeeAlso({ GreenHouse.class })
After I added that I started getting the results I wanted.
I also tried this without generics or just using the Super Class but this did not work either. Interestingly I found that:
Stack trace of error you get with the House based version over the fold:
https://github.com/nebnagrom/jaxbInheritance
In this contrived example we have a Super Class House which has a member variable which is a String and an @XmlRootElement annotation. There are three child Classes of House:
- BlueHouse which has an additional Integer
- RedHouse which has an additional String
- GreenHouse which has an additional Boolean
The issue occured once I started trying to return HousingEstate objects from my RESTful resource. When you invoked the resource you only got back member variables from the House class, i.e. something like this:
{"houses":[{"houseName":"first blue"},{"houseName":"2 blue"}]}
When what I wanted was more like:
{"houses":[{"houseName":"first blue", "blueAttribute":1},
{"houseName":"2 blue", "blueAttribute":2}]}
After a bit of digging I found that I needed to add another annotation on the House class - @XMLSeeAlso like this:@XmlSeeAlso({ GreenHouse.class })
After I added that I started getting the results I wanted.
I also tried this without generics or just using the Super Class but this did not work either. Interestingly I found that:
- Using no generics meant that I got House member variables only, even when I annotated BlueHouse with annotation and added BlueHouses to the collection
- Using the parent class as the Generic gave me Marshalling exceptions, probably to be expected though.
Stack trace of error you get with the House based version over the fold:
Labels:
generics,
inheritance,
Java,
JAXB,
Jersey,
programming,
REST
Subscribe to:
Posts (Atom)