Ok, I tried to register Jackson, like this:
public void testGetBookWithJSONDatabinding() {
List<Object> providers = new ArrayList<Object>();
// add custom providers if any
providers.add(JacksonJsonProvider.class);
WebClient client = WebClient.create(ENDPOINT_ADDRESS, providers);
client.accept("application/json");
client.path("shelf/book");
Book book = client.query("id", 123L).get(Book.class);
assertEquals(123L, book.getId());
}
...but then I got this exception:
ResponseProcessingException: No message body reader has been found for
class CXF_Test.cxf_test.Book, ContentType: application/json
Again, I cannot use spring, so the doc page at:
http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Jackson
was not too helpful, except pointing out the proper provider class name.
Thanks,
Chris
On Wed, Jul 15, 2015 at 2:50 AM, Sergey Beryozkin <[email protected]> wrote:
> CXF JAX-RS supports registered custom providers, the default JSONProvider is
> Jettison based and depends on JAXB, register Jackson instead if needed
> Sergey
> On 15/07/15 02:55, Chris Wolf wrote:
>>
>> No, it's just a plain POJO with no annotations. I'm pretty sure I
>> used Jackson to handle JSON-to-POJO and POJO-to_JSON without requiring
>> annotations. That's not supported in CXF/JAX-RS?
>>
>> Thanks
>>
>> Chris
>>
>> On Tue, Jul 14, 2015 at 2:59 PM, Sergey Beryozkin <[email protected]>
>> wrote:
>>>
>>> CXF JSONProvider only supports JAXB annotated beans, with XmlRootElement,
>>> is
>>> Book.class in your code below a JAXB bean ?
>>> Sergey
>>> On 14/07/15 18:26, Chris Wolf wrote:
>>>>
>>>>
>>>> Again, referring to the example code at:
>>>>
>>>> https://cwiki.apache.org/confluence/display/CXF20DOC/JAXRS+Testing
>>>>
>>>> This client code works:
>>>>
>>>> @Test
>>>> public void testGetBookWithProxy() {
>>>> MyJaxrsResource client =
>>>> JAXRSClientFactory.create(ENDPOINT_ADDRESS, MyJaxrsResource.class);
>>>>
>>>>
>>>> WebClient.getConfig(client).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
>>>> Boolean.TRUE);
>>>> WebClient.getConfig(client).setBus(bus);
>>>> Response r = client.getBook("123");
>>>> String bookJSON = r.readEntity(String.class);
>>>> log.info("JAXRS Client result: {}", bookJSON);
>>>> }
>>>>
>>>> ...but this client code (which should try to unmarshall to object)
>>>> doesn't
>>>> work:
>>>>
>>>> @Test
>>>> public void testGetBookWithWebClient() {
>>>> List<Object> providers = new ArrayList<Object>();
>>>> // add custom providers if any
>>>> providers.add(JSONProvider.class);
>>>>
>>>> WebClient client = WebClient.create(ENDPOINT_ADDRESS,
>>>> providers);
>>>> client.accept("application/json");
>>>> client.path("shelf/book");
>>>> Book book = client.query("id", 123L).get(Book.class);
>>>> assertEquals(123L, book.getId());
>>>> }
>>>>
>>>>
>>>> The error is:
>>>>
>>>> ResponseProcessingException: No message body reader has been found for
>>>> class CXF_Test.cxf_test.Book, ContentType: application/json
>>>>
>>>> However, as can be seen, I configured the "JSONProvider", which I
>>>> thought would unmarshal JSON to POJOs.
>>>>
>>>> Any ideas?
>>>>
>>>
>>>
>>> --
>>> Sergey Beryozkin
>>>
>>> Talend Community Coders
>>> http://coders.talend.com/
>>>
>>> Blog: http://sberyozkin.blogspot.com
>
>