Allow for bundles with no name in java api

This commit is contained in:
Jeremy Lakeman 2016-07-25 15:39:27 +09:30
parent a854105598
commit 51947dc6cb
3 changed files with 22 additions and 17 deletions

View File

@ -91,23 +91,25 @@ public class JSONTableScanner {
HashMap<String,Object> rowMap = new HashMap<String,Object>(row.length);
for (int i = 0; i < row.length; ++i) {
Column col = columns[i];
Object value = null;
if (col != null) {
Object value;
if (col.supported)
value = JSONTokeniser.narrow(row[i], col.type, col.opts);
else {
value = JSONTokeniser.narrow(row[i], col.opts);
try {
value = value == null ? null : col.type.getConstructor(value.getClass()).newInstance(value);
}
catch (InvocationTargetException e) {
throw new JSONInputException("invalid column value: " + col.label + "=\"" + value + "\"", e.getTargetException());
}
catch (Exception e) {
throw new JSONInputException("invalid column value: " + col.label + "=\"" + value + "\"", e);
try {
if (col.supported)
value = JSONTokeniser.narrow(row[i], col.type, col.opts);
else {
value = JSONTokeniser.narrow(row[i], col.opts);
if (value != null)
value = col.type.getConstructor(value.getClass()).newInstance(value);
}
rowMap.put(col.label, value);
} catch (JSONInputException e){
throw new JSONInputException("invalid column value: " + col.label + "; " + e.getMessage(), e);
} catch (InvocationTargetException e) {
throw new JSONInputException("invalid column value: " + col.label + "=\"" + value + "\"", e.getTargetException());
} catch (Exception e) {
throw new JSONInputException("invalid column value: " + col.label + "=\"" + value + "\"", e);
}
rowMap.put(col.label, value);
}
}
return rowMap;

View File

@ -169,8 +169,11 @@ public class JSONTokeniser {
assert !cls.isAssignableFrom(Token.class); // can only narrow to values
if (tok == Token.EOF)
throw new UnexpectedEOFException(cls);
if (opts == Narrow.ALLOW_NULL && (tok == null || tok == Token.NULL))
return null;
if (tok == null || tok == Token.NULL){
if (opts == Narrow.ALLOW_NULL)
return null;
throw new UnexpectedTokenException(tok, cls);
}
if (tok instanceof Token)
throw new UnexpectedTokenException(tok, cls);
// Convert:

View File

@ -64,7 +64,7 @@ public class RhizomeBundleList {
.addColumn("filehash", FileHash.class, JSONTokeniser.Narrow.ALLOW_NULL)
.addColumn("sender", SubscriberId.class, JSONTokeniser.Narrow.ALLOW_NULL)
.addColumn("recipient", SubscriberId.class, JSONTokeniser.Narrow.ALLOW_NULL)
.addColumn("name", String.class);
.addColumn("name", String.class, JSONTokeniser.Narrow.ALLOW_NULL);
this.sinceToken = since_token;
}