How to fix Expected start-union. Got VALUE_NUMBER_INT when converting JSON to Avro on the command line?

后端 未结 4 2073
感动是毒
感动是毒 2020-11-27 17:01

I\'m trying to validate a JSON file using an Avro schema and write the corresponding Avro file. First, I\'ve defined the following Avro schema named user.avsc:<

4条回答
  •  旧巷少年郎
    2020-11-27 17:39

    I have implemented union and its validation , just create a union schema and pass its values through postman . resgistry url is the url which you specify for properties of kafka , u also can pass dynamic values to your schema

    RestTemplate template = new RestTemplate();
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpEntity entity = new HttpEntity(headers);
            ResponseEntity response = template.exchange(""+registryUrl+"/subjects/"+topic+"/versions/"+version+"", HttpMethod.GET, entity, String.class);
            String responseData = response.getBody();
            JSONObject jsonObject = new JSONObject(responseData);
            JSONObject jsonObjectResult = new JSONObject(jsonResult);
            String getData = jsonObject.get("schema").toString();
            Schema.Parser parser = new Schema.Parser();
            Schema schema = parser.parse(getData);
            GenericRecord genericRecord = new GenericData.Record(schema);
            schema.getFields().stream().forEach(field->{
                genericRecord.put(field.name(),jsonObjectResult.get(field.name()));
            });
            GenericDatumReaderreader = new GenericDatumReader(schema);
            boolean data = reader.getData().validate(schema,genericRecord );
    

提交回复
热议问题