use of org.jooq.JSON in project jOOQ by jOOQ.
the class AbstractResult method format0.
/**
* @param value The value to be formatted
* @param visual Whether the formatted output is to be consumed visually
* (HTML, TEXT) or by a machine (CSV, JSON, XML)
*/
private static final String format0(Object value, boolean changed, boolean visual) {
// [#2741] TODO: This logic will be externalised in new SPI
String formatted = changed && visual ? "*" : "";
if (value == null) {
formatted += visual ? "{null}" : null;
} else if (value.getClass() == byte[].class) {
formatted += DatatypeConverter.printBase64Binary((byte[]) value);
} else if (value.getClass().isArray()) {
// [#6545] Nested arrays are handled recursively
formatted += Arrays.stream((Object[]) value).map(f -> format0(f, false, visual)).collect(joining(", ", "[", "]"));
} else if (value instanceof EnumType) {
EnumType e = (EnumType) value;
formatted += e.getLiteral();
} else if (value instanceof List) {
List<?> l = (List<?>) value;
formatted += l.stream().map(f -> format0(f, false, visual)).collect(joining(", ", "[", "]"));
} else if (value instanceof Record) {
Record r = (Record) value;
formatted += Arrays.stream(r.intoArray()).map(f -> format0(f, false, visual)).collect(joining(", ", "(", ")"));
} else // [#6080] Support formatting of nested ROWs
if (value instanceof Param) {
formatted += format0(((Param<?>) value).getValue(), false, visual);
} else // [#5238] Oracle DATE is really a TIMESTAMP(0)...
if (value instanceof Date) {
Date d = (Date) value;
String date = value.toString();
if (Date.valueOf(date).equals(value))
formatted += date;
else
formatted += new Timestamp(d.getTime());
} else {
formatted += value.toString();
}
return formatted;
}
use of org.jooq.JSON in project jOOQ by jOOQ.
the class AbstractResult method formatJSON0.
private static final void formatJSON0(Object value, Writer writer, JSONFormat format) throws java.io.IOException {
// [#2741] TODO: This logic will be externalised in new SPI
if (value instanceof byte[]) {
byte[] a = (byte[]) value;
JSONValue.writeJSONString(DatatypeConverter.printBase64Binary(a), writer);
} else // [#6563] Arrays can be serialised natively in JSON
if (value instanceof Object[]) {
Object[] array = (Object[]) value;
writer.append('[');
for (int i = 0; i < array.length; i++) {
if (i > 0)
writer.append(',');
formatJSON0(array[i], writer, format);
}
writer.append(']');
} else // [#7782] Nested records should generate nested JSON data structures
if (value instanceof Formattable) {
Formattable f = (Formattable) value;
f.formatJSON(writer, format);
} else if (value instanceof JSON && !format.quoteNested()) {
writer.write(((JSON) value).data());
} else if (value instanceof JSONB && !format.quoteNested()) {
writer.write(((JSONB) value).data());
} else {
JSONValue.writeJSONString(value, writer);
}
}
Aggregations