Hello! I don't see any obvious problems with your scala code. What error message are you getting?
For the question "How can I get Avro schema from byte array?", did you mean to ask how you can get a datum from your byte array? The schema is not serialized alongside the binary data, so it needs to be sent via another channel. For example, Avro files have the schema in the file metadata, but messaging systems (like Kafka) typically use a schema registry to centralize and store schemas separately. All my best, Ryan On Mon, Jul 25, 2022 at 11:28 AM Niko Nikolov <[email protected]> wrote: > > I am developing an e-commerce site and faced this issue. Here is my code. > > def toBytes[A](a: A, schema: => org.apache.avro.Schema) = { > System.out.println("===============toBytes==============") > val out = new ByteArrayOutputStream() > val encoder = EncoderFactory.get().binaryEncoder(out, null) > SessionDto.getClassSchema > val writer = new SpecificDatumWriter[A](schema) > writer.write(a, encoder) > encoder.flush() > out.close() > out.toByteArray > } > def fromBytes[A](bytes: Array[Byte], schema: => org.apache.avro.Schema) > = { > val reader = new SpecificDatumReader[A](schema) > val decoder = DecoderFactory.get().binaryDecoder(bytes, null) > reader.read(null.asInstanceOf[A], decoder) > } > > From Avro to byte array is okay but otherwise getting an error. > > Please help me if you have any solution. How can I get Avro schema from > byte array?
