Search in sources :

Example 1 with JsonValue

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;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 2 with JsonValue

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: ");
                }
        }
    }
}
Also used : JsonException(org.activityinfo.json.JsonException) JsonValue(org.activityinfo.json.JsonValue)

Example 3 with JsonValue

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;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 4 with JsonValue

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();
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 5 with JsonValue

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;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Aggregations

JsonValue (org.activityinfo.json.JsonValue)117 Test (org.junit.Test)24 ResourceId (org.activityinfo.model.resource.ResourceId)19 FormClass (org.activityinfo.model.form.FormClass)13 FormField (org.activityinfo.model.form.FormField)9 FieldValue (org.activityinfo.model.type.FieldValue)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 QuantityType (org.activityinfo.model.type.number.QuantityType)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Annotation (java.lang.annotation.Annotation)3 ArrayList (java.util.ArrayList)3 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)3 JaxRsJsonReader (org.activityinfo.server.endpoint.rest.JaxRsJsonReader)3 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)3 EmbeddedEntity (com.google.appengine.api.datastore.EmbeddedEntity)2 URL (java.net.URL)2 JsonException (org.activityinfo.json.JsonException)2 JsonMappingException (org.activityinfo.json.JsonMappingException)2