Please ignore, I have found the solution.
*Regards,*
*Prateek Rajput*
On Sun, Mar 7, 2021 at 10:03 PM Prateek Rajput
wrote:
> Hi Everyone,
> In our use-case we encode avro pojo to byteArray and then push it to
> Kafka, but when I am trying to decode this with slightly updated avro pojo
> (only one new Double field is added with default value 0), I am
> getting ArrayIndexOutOfBoundException.
> Now I know this might be expected as we are not transferring avro schema
> in any header, so the exception might be legit.
> But I do not want any down time in my system and want to deploy my changes
> with new pojo. Is there any way I can do that.
> For reference... Our Utility class for encoding/decoding
>
> import org.apache.avro.file.SeekableByteArrayInput;
> import org.apache.avro.io.BinaryDecoder;
> import org.apache.avro.io.BinaryEncoder;
> import org.apache.avro.io.DecoderFactory;
> import org.apache.avro.io.EncoderFactory;
> import org.apache.avro.specific.SpecificDatumReader;
> import org.apache.avro.specific.SpecificDatumWriter;
> import java.io.ByteArrayOutputStream;
> import java.io.IOException;
>
> public class AvroUtils {
>
> public static byte[] encode(C value, Class c) throws IOException {
> ByteArrayOutputStream byteArrayOutputStream = new
> ByteArrayOutputStream();
> BinaryEncoder binaryEncoder =
> EncoderFactory.get().binaryEncoder(byteArrayOutputStream, null);
> SpecificDatumWriter datumWriter = new SpecificDatumWriter<>(c);
> datumWriter.write(value, binaryEncoder);
> binaryEncoder.flush();
> return byteArrayOutputStream.toByteArray();
> }
>
> public static C decode(byte[] byteArray, Class c) throws
> IOException {
> SeekableByteArrayInput byteArrayInputStream = new
> SeekableByteArrayInput(byteArray);
> BinaryDecoder binaryDecoder =
> DecoderFactory.get().binaryDecoder(byteArrayInputStream, null);
> SpecificDatumReader datumReader = new SpecificDatumReader<>(c);
> return datumReader.read(null, binaryDecoder);
> }
> }
>
> Avro version - 1.7.7
>
>
> *Regards,*
> *Prateek Rajput*
>
--
*-*
*This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they are
addressed. If you have received this email in error, please notify the
system manager. This message contains confidential information and is
intended only for the individual named. If you are not the named addressee,
you should not disseminate, distribute or copy this email. Please notify
the sender immediately by email if you have received this email by mistake
and delete this email from your system. If you are not the intended
recipient, you are notified that disclosing, copying, distributing or
taking any action in reliance on the contents of this information is
strictly prohibited.*
*Any views or opinions presented in this
email are solely those of the author and do not necessarily represent those
of the organization. Any information on shares, debentures or similar
instruments, recommended product pricing, valuations and the like are for
information purposes only. It is not meant to be an instruction or
recommendation, as the case may be, to buy or to sell securities, products,
services nor an offer to buy or sell securities, products or services
unless specifically stated to be so on behalf of the Flipkart group.
Employees of the Flipkart group of companies are expressly required not to
make defamatory statements and not to infringe or authorise any
infringement of copyright or any other legal right by email communications.
Any such communication is contrary to organizational policy and outside the
scope of the employment of the individual concerned. The organization will
not accept any liability in respect of such communication, and the employee
responsible will be personally liable for any damages or other liability
arising.*
*Our organization accepts no liability for the
content of this email, or for the consequences of any actions taken on the
basis of the information *provided,* unless that information is
subsequently confirmed in writing. If you are not the intended recipient,
you are notified that disclosing, copying, distributing or taking any
action in reliance on the contents of this information is strictly
prohibited.*
_-_