You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Dean Ericson (JIRA)" <ji...@apache.org> on 2015/06/24 12:32:04 UTC

[jira] [Commented] (AVRO-924) permit reading & writing arbitrary JSON as binary Avro data

    [ https://issues.apache.org/jira/browse/AVRO-924?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14599225#comment-14599225 ] 

Dean Ericson commented on AVRO-924:
-----------------------------------

This doesn't seem to work when using a more typical json example.  Here is the json I used that seems to be still broken.

{code}
String json = "{\"cost\": 0, \"stamp\": {\"hour\": 12, \"second\": 0}}";
{code}

Here is my test

{code}
	public static String jsonToAvro(String json, Schema schema)
			throws IOException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		PrintStream out = new PrintStream(new BufferedOutputStream(baos));
		GenericDatumReader<Object> reader = new GenericDatumReader<Object>(schema);
		InputStream input = new ByteArrayInputStream(json.getBytes("utf-8"));
		JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(schema,input);
		GenericDatumWriter<Object> writer = new GenericDatumWriter<Object>(schema);
		Encoder e = EncoderFactory.get().binaryEncoder(out, null);
		Object datum = null;
		while (true) {
			try {
				datum = reader.read(datum, jsonDecoder);
			} catch (EOFException eofException) {
				break;
			}
			writer.write(datum, e);
			e.flush();
		}
		return baos.toString("utf-8");
	}
{code}

I notice that the existing tests use the following:
{code}
 private static final String JSON = 
    "\"Long string implies readable length encoding.\"\n";
{code}
I would recommend updating the tests and use more 'complex' json examples

> permit reading & writing arbitrary JSON as binary Avro data
> -----------------------------------------------------------
>
>                 Key: AVRO-924
>                 URL: https://issues.apache.org/jira/browse/AVRO-924
>             Project: Avro
>          Issue Type: New Feature
>          Components: java
>            Reporter: Doug Cutting
>            Assignee: Doug Cutting
>             Fix For: 1.6.0
>
>         Attachments: AVRO-924.patch
>
>
> It would be useful to permit reading and writing arbitrary JSON data as binary Avro data.  JSON is a popular data interchange format but can be rather big and slow to process in some cases, e.g., for numeric data.  Avro can provide a smaller and faster to process binary format for JSON data.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)