use of org.spf4j.base.avro.JThrowable in project spf4j by zolyfarkas.
the class SpecificRecordAppenderTest method testSpecificRecordAppender.
@Test
public void testSpecificRecordAppender() throws IOException {
JThrowable jThrowable = new JThrowable(null, null, null, null, null);
LOG.debug("Broken Object", jThrowable);
SpecificRecordAppender ap = new SpecificRecordAppender();
StringBuilder sb = new StringBuilder();
ap.append(jThrowable, sb);
String str = sb.toString();
Assert.assertThat(str, Matchers.containsString("SerializationError"));
Assert.assertThat(str, Matchers.containsString("java.lang.NullPointerException"));
}
use of org.spf4j.base.avro.JThrowable in project spf4j by zolyfarkas.
the class SpecificRecordAppender method writeSerializationError.
@SuppressFBWarnings("ITC_INHERITANCE_TYPE_CHECKING")
static void writeSerializationError(final Object object, final StringBuilder sb, final Exception ex) throws IOException {
if (STRICT_SERIALIZATION) {
if (ex instanceof IOException) {
throw (IOException) ex;
} else if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
} else {
throw new IllegalStateException(ex);
}
}
sb.setLength(0);
sb.append("{\"SerializationError\":\n");
try (AppendableOutputStream bos = new AppendableOutputStream(sb, Charsets.UTF_8)) {
JThrowable at = Converters.convert(ex);
Schema schema = at.getSchema();
SpecificDatumWriter<SpecificRecord> writer = new SpecificDatumWriter<>(schema);
JsonEncoder jsonEncoder = EF.jsonEncoder(schema, bos, true);
writer.write(at, jsonEncoder);
jsonEncoder.flush();
}
sb.append(",\n");
sb.append("\"ObjectAsString\":\n\"");
EscapeJsonStringAppendableWrapper escaper = new EscapeJsonStringAppendableWrapper(sb);
escaper.append(object.toString());
sb.append("\"}");
}
Aggregations