Accessing nested fields in Avro genericrecord (Java / Scala)
•
Java
I have a genericrecord with nested fields When I use genericrecord When get (1), it returns an object containing nested Avro data
I want to be able to access this object, such as genericrecord get(1). Get (0), but I can't because Avro returns an object
Is there a simple way?
When I execute something like returnedobject Get ("item") indicates that item is not a member of returnedobject
Solution
I came up with a way Convert the returned object to genericrecord
Example (Scala):
val data_ nestedObj =(data.get(“nestedObj)).asInstanceOf [GenericRecord]
I can then access the nested fields in the new genericrecord by doing the following:
data_ nestedObj. get( “nestedField”)
It worked well for me
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码