[
https://issues.apache.org/jira/browse/AVRO-860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13066296#comment-13066296
]
Scott Carey commented on AVRO-860:
----------------------------------
Sorry, I should have noticed this earlier: This was fixed in AVRO-851
The test below fails if I revert AVRO-851 on trunk. AVRO-851 likely fixes the
issue you see too. I am not sure if AVRO-851 made it into 1.5.2's release
candidate.
AVRO-851 did not switch out to Jackson, I think that is still a valuable
improvement.
However, it appears that the patch here alters the output -- it does not escape
the character: '\u2013', leaving it as a literal utf8 char ('–'). Is it
required to escape unicode characters in this range? Jackson apparently does
not in the default configuration.
{code}
@Test
public void testUtf8StringPrint() {
Schema s = Schema.parse("{\"type\":\"record\", \"name\":\"foo\",
\"fields\": [{\"name\":\"bar\", \"type\":[\"null\",\"string\"]}]}");
GenericRecord foo = new GenericData.Record(s);
foo.put(0, new Utf8("unicode char-> \u2013 <-"));
assertEquals("{\"bar\": \"unicode char-> \\u2013 <-\"}", foo.toString());
}
{code}
> Invalid JSON when printing out records with unicode
> ---------------------------------------------------
>
> Key: AVRO-860
> URL: https://issues.apache.org/jira/browse/AVRO-860
> Project: Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.5.1
> Reporter: Miki Tebeka
> Labels: java, json, unicode
> Attachments: AVRO-860.diff, AVRO-860.diff, m.avro
>
>
> I have an avro file, that when printed returns invalid JSON.
> The code for iterating and printing is:
> {code}
> DatumReader<GenericRecord> reader = new
> GenericDatumReader<GenericRecord>();
> DataFileReader<GenericRecord> dataFileReader =
> new DataFileReader<GenericRecord>(data, reader);
> while (dataFileReader.hasNext()) {
> System.out.println(dataFileReader.next().toString());
> }
> {code}
> and the relevant JSON snippet is
> {code}
> "description": "Move™ offers advertisers the opportunity to deliver
> messages to consumers at a time when consumers are making the biggest
> purchases of their lives\uMOVE™ OFFERS ADVERTISERS THE OPPORTUNITY TO DELIVER
> MESSAGES TO CONSUMERS AT A TIME WHEN CONSUMERS ARE MAKING THE BIGGEST
> PURCHASES OF THEIR LIVES—OR REMODELING, REDECORATING AND MAINTAINING THEIR
> MOST IMPORTANT ASSETS.or remodeling, redecorating and maintaining their most
> important assets.",
> {code}
> (The \uMOVE is the problematic part).
> However if I do:
> {code}
> GenericRecord record = dataFileReader.next();
> Utf8 desc = (Utf8)record.get("description");
> System.out.println(desc);
> {code}
> Then I get
> {code}
> Move™ offers advertisers the opportunity to deliver messages to consumers at
> a time when consumers are making the biggest purchases of their lives—or
> remodeling, redecorating and maintaining their most important assets.
> {code}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira