Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json to avro conversion

Tags:

java

json

avro

I'm converting Json to avro. I have json data in JSONArray. So while converting it into byte array i'm facing the problem.

below is my code:

static byte [] fromJsonToAvro(JSONArray json, String schemastr) throws Exception {

ExcelToJson ejj = new ExcelToJson();
List<String> list = new ArrayList<String>();


if (json != null) { 
    int len = json.length();
    for (int i=0;i<len;i++){ 
        list.add(json.get(i).toString());
    } 
}


InputStream input = new ByteArrayInputStream(list.getBytes()); //json.toString().getBytes()

 DataInputStream din = new DataInputStream(input); 
                  .
                  . 
                  .//rest of the logic

So how can i do it? How to convert JsonArray object to bytes(i.e., how to use getBytes() method for JsonArray objects). The above code giving an error at list.getBytes() and saying getBytes() is undifined for list.

like image 285
shree11 Avatar asked Apr 17 '15 06:04

shree11


1 Answers

For an on-line json to avro converter check the following URL

http://avro4s-ui.landoop.com

It is using the library avro4s that offers a lot of conversions including json=>avro

like image 152
Antonios Chalkiopoulos Avatar answered Oct 04 '22 00:10

Antonios Chalkiopoulos