use of org.yuanheng.cookjson.TextJsonParser in project jaqy by Teradata.
the class HelperConfigUtils method load.
public static void load(HelperManager manager, String json) throws IOException {
JsonValue v;
CookJsonParser p = new TextJsonParser(new StringReader(json), json.length());
p.next();
v = p.getValue();
p.close();
load(manager, (JsonArray) v);
}
use of org.yuanheng.cookjson.TextJsonParser in project jaqy by Teradata.
the class JsonUtils method print.
public static long print(Globals globals, CookJsonGenerator g, JaqyResultSet rs, long limit) throws SQLException {
JaqyResultSetMetaData metaData = rs.getMetaData();
int columns = metaData.getColumnCount();
String[] headers = new String[columns];
boolean[] jsonCheck = new boolean[columns];
for (int i = 0; i < columns; ++i) {
headers[i] = metaData.getColumnLabel(i + 1);
jsonCheck[i] = metaData.isJson(i + 1);
}
g.writeStartArray();
long count = 0;
if (limit == 0)
limit = Long.MAX_VALUE;
while (rs.next() && count < limit) {
++count;
g.writeStartObject();
for (int i = 0; i < columns; ++i) {
Object obj = rs.getObject(i + 1);
if (obj != null && jsonCheck[i]) {
globals.log(Level.INFO, "Column " + (i + 1) + " is a JSON column: " + obj.getClass());
String str = null;
// We only deal with textual form of JSON here.
if (obj instanceof Clob) {
Clob clob = (Clob) obj;
str = clob.getSubString(1, (int) clob.length());
clob.free();
} else {
str = obj.toString();
}
if (str != null) {
// Now convert str to JsonValue
try {
CookJsonParser p = new TextJsonParser(new StringReader(str));
p.next();
obj = p.getValue();
p.close();
} catch (Exception ex) {
globals.log(Level.INFO, ex);
}
}
}
print(g, headers[i], obj);
}
g.writeEnd();
}
g.writeEnd();
g.flush();
return count;
}
Aggregations