Json 문자열을 Avro 스키마가있는 일반 Java 객체로 변환하려고합니다.Json String to Java Object Avro
아래 코드는 제 코드입니다. "예상 시작 노조있어 VALUE_NUMBER_FLOAT org.apache.avro.AvroTypeException을."예외를
String json = "{\"foo\": 30.1, \"bar\": 60.2}";
String schemaLines = "{\"type\":\"record\",\"name\":\"FooBar\",\"namespace\":\"com.foo.bar\",\"fields\":[{\"name\":\"foo\",\"type\":[\"null\",\"double\"],\"default\":null},{\"name\":\"bar\",\"type\":[\"null\",\"double\"],\"default\":null}]}";
InputStream input = new ByteArrayInputStream(json.getBytes());
DataInputStream din = new DataInputStream(input);
Schema schema = Schema.parse(schemaLines);
Decoder decoder = DecoderFactory.get().jsonDecoder(schema, din);
DatumReader<Object> reader = new GenericDatumReader<Object>(schema);
Object datum = reader.read(null, decoder);
내가 얻을.
스키마에 공용체가 없으면 동일한 코드가 작동합니다. 누군가 설명하고 해결책을 줄 수 있습니까?
http://avro.apache.org/docs/1.7.6/spec.html#json_encoding에서 알기로, Json 인코딩 조합이 다르다는 것을 알고 있지만 어떤 방법이 있는지 알아 내려고합니다. json 문자열을 객체로 변환 할 수 있습니다. –
FYI,'jsonDecoder()'의 오버로드는 json String을 받아 들인다; 스트림으로 변환 할 필요가 없습니다. – jaco0646