Hi JSONProvider is not really meant to be used as a utility class, the way you're using it, I suggested it for you be able to get the exception bean populated quickly. I think all the code is there at the ProviderFactory level for users be able to do JSONProvider<Bar> but there could be some custom providers extending JSONProvider out there so properly parameterizing JSONProvider can have side-effects. It has to be done eventually. In reality, it is mainly the users doing the unit testing which have to write the rather 'clumsy' code similar to the one you did.
I guess what you really would like to do is to write some simple Jettison-specific code to be used inside of your exception mapper which will use a statically allocated JAXBContext (for your exception data bean) to get an Unmarshaller and then use it to read from a basic XMLStreamReader created by Jettison, please have a look at JSOnProvider.readFrom, 2/3 lines of code can be found there showing how to create a basic JSON-aware reader hope it helps, Sergey On Mon, Mar 1, 2010 at 10:19 PM, DmitryM <[email protected]> wrote: > > Sergey, > > Looks like parametrizing JSONProvider could be a good idea, but I managed > to > get away with the following code: > > MyExceptionWrapper unmarshalledObject = > (MyExceptionWrapper)jsonProvider.readFrom( > (Class)((Object)new > MyExceptionWrapper()).getClass(), > null, null, > MediaType.APPLICATION_JSON_TYPE, null, > (InputStream)new > ByteArrayInputStream(response.getEntity().toString().getBytes())); > exceptionWrapper = > (MyExceptionWrapper)unmarshalledObject; > exClass = (Class<PimsCheckedException>) > Class.forName(exceptionWrapper.exceptionClassName); > > It does look a little ugly (especially because I had to cast my class to > Object since JSONProvider implements ), but it works. > Please, if you have a few minutes, let me know if it could have been done > in > a simpler way (I could not figure out how to get a specific writer for a > specific class) > > Thanks, > Dmitry > > > Sergey Beryozkin-5 wrote: > > > > Please see > > > > > https://jsr311.dev.java.net/nonav/releases/1.0/javax/ws/rs/ext/MessageBodyReader.html#isReadable(java.lang.Class,%20java.lang.reflect.Type,%20java.lang.annotation.Annotation[],%20javax.ws.rs.core.MediaType)<https://jsr311.dev.java.net/nonav/releases/1.0/javax/ws/rs/ext/MessageBodyReader.html#isReadable%28java.lang.Class,%20java.lang.reflect.Type,%20java.lang.annotation.Annotation%5B%5D,%20javax.ws.rs.core.MediaType%29> > > > > -- > View this message in context: > http://old.nabble.com/Unmarshal-WebApplicationException-Response-JSON-entity-tp27726278p27749802.html > Sent from the cxf-user mailing list archive at Nabble.com. > >
