mirror of https://github.com/apache/nifi.git
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:
parent
bfd6c0aef7
commit
c3754c3921
|
@ -33,6 +33,7 @@ import org.apache.avro.generic.GenericData;
|
||||||
import org.apache.avro.generic.GenericDatumWriter;
|
import org.apache.avro.generic.GenericDatumWriter;
|
||||||
import org.apache.avro.generic.GenericRecord;
|
import org.apache.avro.generic.GenericRecord;
|
||||||
import org.apache.avro.io.DatumWriter;
|
import org.apache.avro.io.DatumWriter;
|
||||||
|
import org.apache.commons.lang3.StringEscapeUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.nifi.annotation.behavior.EventDriven;
|
import org.apache.nifi.annotation.behavior.EventDriven;
|
||||||
import org.apache.nifi.annotation.behavior.InputRequirement;
|
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");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");
|
||||||
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
return "\"" + dateFormat.format((Date) value) + "\"";
|
return "\"" + dateFormat.format((Date) value) + "\"";
|
||||||
|
} else if (value instanceof String) {
|
||||||
|
return "\"" + StringEscapeUtils.escapeJson((String) value) + "\"";
|
||||||
} else {
|
} else {
|
||||||
return "\"" + value.toString() + "\"";
|
return "\"" + value.toString() + "\"";
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class CassandraQueryTestUtil {
|
||||||
createRow("user1", "Joe", "Smith", Sets.newHashSet("jsmith@notareal.com"),
|
createRow("user1", "Joe", "Smith", Sets.newHashSet("jsmith@notareal.com"),
|
||||||
Arrays.asList("New York, NY", "Santa Clara, CA"),
|
Arrays.asList("New York, NY", "Santa Clara, CA"),
|
||||||
new HashMap<Date, String>() {{
|
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),
|
}}, false, 1.0f, 2.0),
|
||||||
createRow("user2", "Mary", "Jones", Sets.newHashSet("mjones@notareal.com"),
|
createRow("user2", "Mary", "Jones", Sets.newHashSet("mjones@notareal.com"),
|
||||||
Collections.singletonList("Orlando, FL"),
|
Collections.singletonList("Orlando, FL"),
|
||||||
|
|
|
@ -140,7 +140,7 @@ public class QueryCassandraTest {
|
||||||
assertEquals("One file should be transferred to success", 1, files.size());
|
assertEquals("One file should be transferred to success", 1, files.size());
|
||||||
assertEquals("{\"results\":[{\"user_id\":\"user1\",\"first_name\":\"Joe\",\"last_name\":\"Smith\","
|
assertEquals("{\"results\":[{\"user_id\":\"user1\",\"first_name\":\"Joe\",\"last_name\":\"Smith\","
|
||||||
+ "\"emails\":[\"jsmith@notareal.com\"],\"top_places\":[\"New York, NY\",\"Santa Clara, CA\"],"
|
+ "\"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},"
|
+ "\"registered\":\"false\",\"scale\":1.0,\"metric\":2.0},"
|
||||||
+ "{\"user_id\":\"user2\",\"first_name\":\"Mary\",\"last_name\":\"Jones\","
|
+ "{\"user_id\":\"user2\",\"first_name\":\"Mary\",\"last_name\":\"Jones\","
|
||||||
+ "\"emails\":[\"mjones@notareal.com\"],\"top_places\":[\"Orlando, FL\"],"
|
+ "\"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("One file should be transferred to success", 1, files.size());
|
||||||
assertEquals("{\"results\":[{\"user_id\":\"user1\",\"first_name\":\"Joe\",\"last_name\":\"Smith\","
|
assertEquals("{\"results\":[{\"user_id\":\"user1\",\"first_name\":\"Joe\",\"last_name\":\"Smith\","
|
||||||
+ "\"emails\":[\"jsmith@notareal.com\"],\"top_places\":[\"New York, NY\",\"Santa Clara, CA\"],"
|
+ "\"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},"
|
+ "\"registered\":\"false\",\"scale\":1.0,\"metric\":2.0},"
|
||||||
+ "{\"user_id\":\"user2\",\"first_name\":\"Mary\",\"last_name\":\"Jones\","
|
+ "{\"user_id\":\"user2\",\"first_name\":\"Mary\",\"last_name\":\"Jones\","
|
||||||
+ "\"emails\":[\"mjones@notareal.com\"],\"top_places\":[\"Orlando, FL\"],"
|
+ "\"emails\":[\"mjones@notareal.com\"],\"top_places\":[\"Orlando, FL\"],"
|
||||||
|
|
Loading…
Reference in New Issue