use of org.apache.pivot.serialization.CSVSerializer in project pivot by apache.
the class CSVSerializerTest method testQuotedQuoteReadObject.
@Test
public void testQuotedQuoteReadObject() throws IOException, SerializationException {
StringBuilder buf = new StringBuilder();
buf.append("a,\"\"\"b\"\"\",c\r\n");
StringReader reader = new StringReader(buf.toString());
CSVSerializer serializer = new CSVSerializer();
serializer.setKeys("A", "B", "C");
List<?> result = serializer.readObject(reader);
@SuppressWarnings("unchecked") Dictionary<String, Object> row = (Dictionary<String, Object>) result.get(0);
assertEquals("a", row.get("A"));
assertEquals("\"b\"", row.get("B"));
assertEquals("c", row.get("C"));
}
use of org.apache.pivot.serialization.CSVSerializer in project pivot by apache.
the class CSVSerializerTest method testQuotedQuoteWriteObject.
@SuppressWarnings("unchecked")
// or it will generate a warning during build with Java 7
@Test
public void testQuotedQuoteWriteObject() throws IOException {
List<Object> items = new ArrayList<>();
items.add(new HashMap<>(new Dictionary.Pair<String, Object>("A", "a"), new Dictionary.Pair<String, Object>("B", "\"b\""), new Dictionary.Pair<String, Object>("C", "c")));
StringWriter writer = new StringWriter();
CSVSerializer serializer = new CSVSerializer();
serializer.setKeys("A", "B", "C");
serializer.writeObject(items, writer);
assertEquals("a,\"\"\"b\"\"\",c\r\n", writer.toString());
}
use of org.apache.pivot.serialization.CSVSerializer in project pivot by apache.
the class CSVSerializerTest method testInlineKeys.
@Test
public void testInlineKeys() throws IOException, SerializationException {
StringBuilder buf = new StringBuilder();
buf.append("A \t, B ,C \n");
buf.append("a1,b1,c1\n");
StringReader reader = new StringReader(buf.toString());
CSVSerializer serializer = new CSVSerializer();
List<?> result = serializer.readObject(reader);
@SuppressWarnings("unchecked") Dictionary<String, Object> row = (Dictionary<String, Object>) result.get(0);
assertEquals(row.get("A"), "a1");
assertEquals(row.get("B"), "b1");
assertEquals(row.get("C"), "c1");
}
use of org.apache.pivot.serialization.CSVSerializer in project pivot by apache.
the class CSVSerializerTest method testQuotedCommaWriteObject.
@SuppressWarnings("unchecked")
// or it will generate a warning during build with Java 7
@Test
public void testQuotedCommaWriteObject() throws IOException {
List<Object> items = new ArrayList<>();
items.add(new HashMap<>(new Dictionary.Pair<String, Object>("A", "a"), new Dictionary.Pair<String, Object>("B", ",b,"), new Dictionary.Pair<String, Object>("C", "c")));
StringWriter writer = new StringWriter();
CSVSerializer serializer = new CSVSerializer();
serializer.setKeys("A", "B", "C");
serializer.writeObject(items, writer);
assertEquals("a,\",b,\",c\r\n", writer.toString());
}
use of org.apache.pivot.serialization.CSVSerializer in project pivot by apache.
the class CSVSerializerTest method testQuotedCommaReadObject.
@Test
public void testQuotedCommaReadObject() throws IOException, SerializationException {
StringBuilder buf = new StringBuilder();
buf.append("a,\",b,\",c\r\n");
StringReader reader = new StringReader(buf.toString());
CSVSerializer serializer = new CSVSerializer();
serializer.setKeys("A", "B", "C");
List<?> result = serializer.readObject(reader);
@SuppressWarnings("unchecked") Dictionary<String, Object> row = (Dictionary<String, Object>) result.get(0);
assertEquals("a", row.get("A"));
assertEquals(",b,", row.get("B"));
assertEquals("c", row.get("C"));
}
Aggregations