[#12930] Fix reading nested top level rows also as binary data

This commit is contained in:
Lukas Eder 2022-02-23 16:26:51 +01:00
parent afe156a7e3
commit e9e86fe2f1
2 changed files with 13 additions and 2 deletions

View File

@ -3782,6 +3782,8 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
static final <R extends Record> R readMultiset(BindingGetResultSetContext<?> ctx, DataType<R> type) throws SQLException {
return DefaultResultBinding.readMultiset(ctx, (AbstractRow<R>) type.getRow(), type.getType(),
// [#12930] Tricky to patch a byte[]. We're patching it in JSONReader, instead
b -> b,
s -> s.startsWith("[") || s.startsWith("{") ? "[" + s + "]" : s,
s -> s.startsWith("<") ? "<result>" + s + "</result>" : s

View File

@ -51,13 +51,12 @@ import static org.jooq.tools.StringUtils.defaultIfBlank;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import jakarta.xml.bind.DatatypeConverter;
import org.jooq.DSLContext;
import org.jooq.Field;
import org.jooq.Fields;
@ -66,6 +65,8 @@ import org.jooq.Result;
import org.jooq.tools.json.ContainerFactory;
import org.jooq.tools.json.JSONParser;
import jakarta.xml.bind.DatatypeConverter;
/**
* A very simple JSON reader based on Simple JSON.
*
@ -154,6 +155,14 @@ final class JSONReader<R extends Record> {
result = new ResultImpl<>(ctx.configuration(), actualRow);
if (records != null) {
// [#12930] Nested ROW emulations can produce scalar values
// when they're of degree 1. This is patched
if (!records.isEmpty()
&& !(records.get(0) instanceof Map)
&& !(records.get(0) instanceof List))
records = asList(records);
for (Object o3 : records) {
if (o3 instanceof Map) {
Map<String, Object> record = (Map<String, Object>) o3;