You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Chandrashekhar Kotekar <sh...@gmail.com> on 2014/08/06 09:45:28 UTC

How to send Avro data as a response from REST web service?

Hi,

I would like to know what is the best way to convert POJO into Avro type
object and send it as an response from REST web service?

I have managed to do following things :

1. Write avsc files and generate POJO from avsc files.

2. Added Avro data provider using @Provider annotation and extending
MessageBodyWriter

3. Wrote following code in writeTo() method of the provider

        @Override
public void writeTo(Object obj, Class classType, Type type, Annotation[]
annotations,
MediaType mediaType, MultivaluedMap map, OutputStream outStream) throws
IOException, WebApplicationException {

Encoder encoder = ENCODER_FACTORY.binaryEncoder(outStream, null);
DatumWriter writer = new ReflectDatumWriter();
 writer.write(obj, encoder);
encoder.flush();
}

I am getting NullPointerException when writer.write(obj, encoder) method is
called. In stacktrace I am not able to find any clue.

How to resolve this issue? or ss there any other way to send Avro data as a
response from REST service?

Regards,
Chandrash3khar Kotekar
Mobile - +91 8600011455

Re: Avro and Jackson dependency

Posted by Doug Cutting <cu...@apache.org>.
Avro currently requires Jackson 1.x.  Jackson 2.x has an incompatible
API in a different package.  The two versions of Jackson do not
conflict so both may be used within a single application.

Whether & when to eventually upgrade Avro to use Jackson 2.x is discussed in:

  https://issues.apache.org/jira/browse/AVRO-1126

Doug

On Thu, Aug 7, 2014 at 9:41 AM, Casadio Phaedra
<Ph...@datamanagementpa.it> wrote:
> After compiling my schema to java, i’ve this error in class files:
>
>
>
> The type org.codehaus.jackson.JsonParser cannot be resolved. It is
> indirectly referenced from required .class files
>
>
>
> In my project i’ve last Jackson version 2.4.1, seems that avro is using a
> real old one?
>
>
>
> Also in generated bean i’ve found some deprecations, it’s normal?
>
>
>
> Thanks Phaedra.

Avro and Jackson dependency

Posted by Casadio Phaedra <Ph...@datamanagementpa.it>.
After compiling my schema to java, i’ve this error in class files:

The type org.codehaus.jackson.JsonParser cannot be resolved. It is indirectly referenced from required .class files

In my project i’ve last Jackson version 2.4.1, seems that avro is using a real old one?

Also in generated bean i’ve found some deprecations, it’s normal?

Thanks Phaedra.