NIFI-4320 - Escape quotes for JSON output in QueryCassandra

Signed-off-by: Matthew Burgess <mattyb149@apache.org>

This closes #2114
This commit is contained in:
Pierre Villard 2017-08-26 17:09:15 +02:00 committed by Matthew Burgess
parent bfd6c0aef7
commit c3754c3921
3 changed files with 6 additions and 3 deletions

View File

@ -33,6 +33,7 @@ import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.DatumWriter;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.nifi.annotation.behavior.EventDriven;
import org.apache.nifi.annotation.behavior.InputRequirement;
@ -497,6 +498,8 @@ public class QueryCassandra extends AbstractCassandraProcessor {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return "\"" + dateFormat.format((Date) value) + "\"";
} else if (value instanceof String) {
return "\"" + StringEscapeUtils.escapeJson((String) value) + "\"";
} else {
return "\"" + value.toString() + "\"";
}

View File

@ -86,7 +86,7 @@ public class CassandraQueryTestUtil {
createRow("user1", "Joe", "Smith", Sets.newHashSet("jsmith@notareal.com"),
Arrays.asList("New York, NY", "Santa Clara, CA"),
new HashMap<Date, String>() {{
put(aMonthPrior, "Set my alarm for a month from now");
put(aMonthPrior, "Set my alarm \"for\" a month from now");
}}, false, 1.0f, 2.0),
createRow("user2", "Mary", "Jones", Sets.newHashSet("mjones@notareal.com"),
Collections.singletonList("Orlando, FL"),

View File

@ -140,7 +140,7 @@ public class QueryCassandraTest {
assertEquals("One file should be transferred to success", 1, files.size());
assertEquals("{\"results\":[{\"user_id\":\"user1\",\"first_name\":\"Joe\",\"last_name\":\"Smith\","
+ "\"emails\":[\"jsmith@notareal.com\"],\"top_places\":[\"New York, NY\",\"Santa Clara, CA\"],"
+ "\"todo\":{\"2016-01-03 05:00:00+0000\":\"Set my alarm for a month from now\"},"
+ "\"todo\":{\"2016-01-03 05:00:00+0000\":\"Set my alarm \\\"for\\\" a month from now\"},"
+ "\"registered\":\"false\",\"scale\":1.0,\"metric\":2.0},"
+ "{\"user_id\":\"user2\",\"first_name\":\"Mary\",\"last_name\":\"Jones\","
+ "\"emails\":[\"mjones@notareal.com\"],\"top_places\":[\"Orlando, FL\"],"
@ -177,7 +177,7 @@ public class QueryCassandraTest {
assertEquals("One file should be transferred to success", 1, files.size());
assertEquals("{\"results\":[{\"user_id\":\"user1\",\"first_name\":\"Joe\",\"last_name\":\"Smith\","
+ "\"emails\":[\"jsmith@notareal.com\"],\"top_places\":[\"New York, NY\",\"Santa Clara, CA\"],"
+ "\"todo\":{\"2016-01-03 05:00:00+0000\":\"Set my alarm for a month from now\"},"
+ "\"todo\":{\"2016-01-03 05:00:00+0000\":\"Set my alarm \\\"for\\\" a month from now\"},"
+ "\"registered\":\"false\",\"scale\":1.0,\"metric\":2.0},"
+ "{\"user_id\":\"user2\",\"first_name\":\"Mary\",\"last_name\":\"Jones\","
+ "\"emails\":[\"mjones@notareal.com\"],\"top_places\":[\"Orlando, FL\"],"