class OrientationOptions {

    public static OrientationOptions parse(JSONObject json) {
        OrientationOptions options = new OrientationOptions();
        if (json == null) return options;

        JSONArray orientations = json.optJSONArray("orientation");
        if (orientations == null) {
            String orientation = json.optString("orientation", Orientation.Default.name);
            options.orientations.add(Orientation.fromString(orientation));
        } else {
            List<Orientation> parsed = new ArrayList<>();
            for (int i = 0; i < orientations.length(); i++) {
                Orientation o = Orientation.fromString(orientations.optString(i, "default"));
                if (o != null) {
                    parsed.add(o);
                }
            }
            options.orientations = parsed;
        }

        return options;
    }

}