0
I’m trying to create a Builder schema, but I don’t know directly how to make one, looking at the Handbook I come across the following code, but I try to implement in my Java code and cannot create.
In case I will show the JSON that is in manual and its Java implementation. I also noticed that there are a quotation marks opening but not closing, I tried to close it but it did not solve the problem, I do not know exactly if it is so the code or they missed the manual.
Example from JSON:
{
"type": "record",
"name": "HandshakeRequest", "namespace":"org.apache.avro.ipc",
"fields": [
{"name": "clientHash",
"type": {"type": "fixed", "name": "MD5", "size": 16}},
{"name": "clientProtocol", "type": ["null", "string"]},
{"name": "serverHash", "type": "MD5"},
{"name": "meta", "type": ["null", {"type": "map", "values": "bytes"}]}
]
}
Example of Java code:
Schema schema = SchemaBuilder
.record("HandshakeRequest").namespace("org.apache.avro.ipc)
.fields()
.name("clientHash").type().fixed("MD5").size(16).noDefault()
.name("clientProtocol").type().nullable().stringType().noDefault()
.name("serverHash").type("MD5")
.name("meta").type().nullable().map().values().bytesType().noDefault()
.endRecord();
Libraries used:
import org.apache.avro.Schema;
import org.apache.avro.SchemaBuilder;
I wanted to know if the implementation of the code is correct, in case I would not like an example of how it would look to implement the above code.
The error that is giving is syntax error and not compilation error, if this is to help in something. I would just like you to help me get the syntax right and explain a little better about how the schema Builder works and the error happens on line 2 of the Java code:
"Illegal line end in string literal"
Which I believe is due to the lack of quotation marks in the manual code:
.record("HandshakeRequest").namespace("org.apache.avro.ipc)
But even closing the quotes occurs an error on this line:
.name("meta").type().nullable().map().values().bytesType().noDefault()
The mistake:
Cannot Resolve method 'name. (java.lang.String)'
I believe the code of the manual is wrong, so I believe it is important to show how to use the Builder for Schemabuilder.