[jOOQ/jOOQ#8829] Loader does not work with binary data in JSON

This commit is contained in:
Lukas Eder 2020-06-25 17:18:03 +02:00
parent 48aa76adc1
commit 463264dab5
2 changed files with 12 additions and 1 deletions

View File

@ -53,6 +53,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.bind.DatatypeConverter;
import org.jooq.DSLContext;
import org.jooq.Field;
import org.jooq.Record;
@ -79,6 +81,7 @@ final class JSONReader {
return read(new StringReader(string));
}
@SuppressWarnings("rawtypes")
final Result<Record> read(final Reader reader) {
try {
@ -154,7 +157,7 @@ final class JSONReader {
result.add(r);
}
else {
List<?> record = (List<?>) o3;
List record = (List) o3;
if (result == null) {
if (f.isEmpty())
@ -164,6 +167,13 @@ final class JSONReader {
}
Record r = ctx.newRecord(f);
// [#8829] LoaderImpl expects binary data to be encoded in base64,
// not according to org.jooq.tools.Convert
for (int i = 0; i < f.size(); i++)
if (f.get(i).getType() == byte[].class && record.get(i) instanceof String)
record.set(i, DatatypeConverter.parseBase64Binary((String) record.get(i)));
r.from(record);
result.add(r);
}

View File

@ -755,6 +755,7 @@ final class LoaderImpl<R extends Record> implements
// [#1627] [#5858] Handle NULL values and base64 encodings
// [#2741] TODO: This logic will be externalised in new SPI
// [#8829] JSON binary data has already been decoded at this point
for (int i = 0; i < row.length; i++)
if (StringUtils.equals(nullString, row[i]))
row[i] = null;