I have a file that uses the Avro binary encoding, and I want to
re-write it using the JSON encoding
in a way that respects the schema in the binary file.
I can read in a record from the binary file and try to create a
Jackson JsonNode:
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.valueToTree(record);
where record is an instance of GenericRecord.
That gives an error "not a union".
If instead I use
JsonNode json = mapper.readTree(record.toString());
I get a valid JsonNode. But if I try to write that out:
JsonEncoder je = new EncoderFactory().jsonEncoder(schema, new
FileOutputStream("my.json"));
jsonWriter.write(json,je);
I get a schema violation, "long where union expected". The schema came
from the original binary file.
So is it possible to create a JsonNode that conforms to a schema? Is
there some better way to create
JsonNodes than using the ObjectMapper methods?
-- Paul
re-write it using the JSON encoding
in a way that respects the schema in the binary file.
I can read in a record from the binary file and try to create a
Jackson JsonNode:
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.valueToTree(record);
where record is an instance of GenericRecord.
That gives an error "not a union".
If instead I use
JsonNode json = mapper.readTree(record.toString());
I get a valid JsonNode. But if I try to write that out:
JsonEncoder je = new EncoderFactory().jsonEncoder(schema, new
FileOutputStream("my.json"));
jsonWriter.write(json,je);
I get a schema violation, "long where union expected". The schema came
from the original binary file.
So is it possible to create a JsonNode that conforms to a schema? Is
there some better way to create
JsonNodes than using the ObjectMapper methods?
-- Paul