Android Open Source - json2view Dynamic View Json Builder

From Project

Back to project page json2view.


The source code is released under:

MIT License

If you think the Android project json2view listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.avocarrot.json2view;
/*  w  w  w .  j  a  v  a 2  s  . c o m*/
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DynamicViewJsonBuilder {

    private String widget = "";
    private List<JSONObject> properties;
    private List<JSONObject> views;

    public DynamicViewJsonBuilder() {
        properties = new ArrayList<>();
        views = new ArrayList<>();

    public DynamicViewJsonBuilder setWidget(String widget) {
        this.widget = widget;
        return this;
    public DynamicViewJsonBuilder addProperty(JSONObject property) {;
        return this;
    public DynamicViewJsonBuilder addView(JSONObject view) {
        return this;

    public JSONObject build() {
        Map<String, Object> map = new HashMap<>();
        map.put("widget", widget);
        map.put("properties", new JSONArray(properties));
        map.put("views", new JSONArray(views));
        return new JSONObject(map);


Java Source Code List