Convert org.apache.avro.util.Utf8 to java.lang.String
Asked Answered
C

1

8

I write a sample with avro library. It generate java class source code User from schema record User.

I want to encode User to byte[], and decode byte[] to User.

When decoding, I've got error message:

java.lang.ClassCastException: org.apache.avro.util.Utf8 cannot be cast to java.lang.String

How to convert org.apache.avro.util.Utf8 to java String ?

Circinus answered 8/9, 2019 at 6:16 Comment(0)
L
12

You can use its method toString()

toString in interface CharSequence

Lemming answered 8/9, 2019 at 6:20 Comment(2)
Hi, if the value is a avro GenericRecord, is there a toGenericRecord() method ?Circinus
@Circinus see code examples codota.com/code/java/classes/org.apache.avro.util.Utf8Lemming

© 2022 - 2024 — McMap. All rights reserved.