use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class JsonReflection method toArray.
private static JsonValue toArray(Object o) {
JsonValue array = Json.createArray();
int length = Array.getLength(o);
for (int i = 0; i < length; i++) {
array.add(toJson(Array.get(o, i)));
}
return array;
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class JsonTokenizer method parseObject.
JsonValue parseObject() throws JsonException {
final JsonValue object = jsonFactory.createObject();
int c = nextNonWhitespace();
if (c != '{') {
throw new JsonException("Payload does not begin with '{'. Got " + c + "(" + Character.valueOf((char) c) + ")");
}
while (true) {
c = nextNonWhitespace();
switch(c) {
case '}':
// We're done.
return object;
case '"':
case '\'':
back(c);
// Ready to start a key.
final String key = nextString(c);
if (nextNonWhitespace() != ':') {
throw new JsonException("Invalid object: expecting \":\"");
}
// TODO(knorton): Make sure this key is not already set.
object.put(key, (JsonValue) nextValue());
switch(nextNonWhitespace()) {
case ',':
break;
case '}':
return object;
default:
throw new JsonException("Invalid object: expecting } or ,");
}
break;
case ',':
break;
default:
if (lenient && (Character.isDigit((char) c) || Character.isLetterOrDigit((char) c))) {
StringBuilder keyBuffer = new StringBuilder();
keyBuffer.append(c);
while (true) {
c = next();
if (Character.isDigit((char) c) || Character.isLetterOrDigit((char) c)) {
keyBuffer.append(c);
} else {
back(c);
break;
}
}
if (nextNonWhitespace() != ':') {
throw new JsonException("Invalid object: expecting \":\"");
}
// TODO(knorton): Make sure this key is not already set.
object.put(keyBuffer.toString(), (JsonValue) nextValue());
switch(nextNonWhitespace()) {
case ',':
break;
case '}':
return object;
default:
throw new JsonException("Invalid object: expecting } or ,");
}
} else {
throw new JsonException("Invalid object: ");
}
}
}
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class PivotModel method toJson.
@Value.Lazy
@Override
public JsonValue toJson() {
JsonValue measures = Json.createArray();
for (MeasureModel measureModel : getMeasures()) {
measures.add(measureModel.toJson());
}
JsonValue dimensions = Json.createArray();
for (DimensionModel dimensionModel : getDimensions()) {
dimensions.add(dimensionModel.toJson());
}
JsonValue object = Json.createObject();
object.put("measures", measures);
object.put("dimensions", dimensions);
return object;
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class PivotModel method fromJson.
public static PivotModel fromJson(JsonValue jsonObject) {
ImmutablePivotModel.Builder model = ImmutablePivotModel.builder();
JsonValue measures = jsonObject.get("measures");
for (int i = 0; i < measures.length(); i++) {
model.addMeasures(MeasureModel.fromJson(measures.get(i)));
}
JsonValue dimensions = jsonObject.get("dimensions");
for (int i = 0; i < dimensions.length(); i++) {
model.addDimensions(DimensionModel.fromJson(dimensions.get(i)));
}
return model.build();
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class DimensionMapping method toJson.
public JsonValue toJson() {
JsonValue object = Json.createObject();
if (formId != null) {
object.put("formId", formId.asString());
}
object.put("formula", formula);
return object;
}
Aggregations