fluid-api/src/main/java/com/fluidbpm/program/api/vo/template/FluidTemplate.java
@Override
    public JSONObject toJsonObject() throws JSONException {

        JSONObject returnVal = new JSONObject();

        //Template Name...
        if(this.getTemplateName() != null)
        {
            returnVal.put(JSONMapping.TEMPLATE_NAME,
                    this.getTemplateName());
        }

        //Template Description...
        if(this.getTemplateDescription() != null)
        {
            returnVal.put(JSONMapping.TEMPLATE_DESCRIPTION,
                    this.getTemplateDescription());
        }

        //Template Comment...
        if(this.getTemplateComment() != null)
        {
            returnVal.put(JSONMapping.TEMPLATE_COMMENT,
                    this.getTemplateComment());
        }

        //Forms and Fields...
        if(this.getFormsAndFields() != null && !this.getFormsAndFields().isEmpty())
        {
            JSONArray jsonArray = new JSONArray();

            for(Form form : this.getFormsAndFields())
            {
                jsonArray.put(form.toJsonObject());
            }

            returnVal.put(JSONMapping.FORMS_AND_FIELDS, jsonArray);
        }

        //User Queries...
        if(this.getUserQueries() != null && !this.getUserQueries().isEmpty())
        {
            JSONArray jsonArray = new JSONArray();

            for(UserQuery userQuery : this.getUserQueries())
            {
                jsonArray.put(userQuery.toJsonObject());
            }

            returnVal.put(JSONMapping.USER_QUERIES, jsonArray);
        }

        //Flows...
        if(this.getFlows() != null && !this.getFlows().isEmpty())
        {
            JSONArray jsonArray = new JSONArray();

            for(Flow flow : this.getFlows())
            {
                jsonArray.put(flow.toJsonObject());
            }

            returnVal.put(JSONMapping.FLOWS, jsonArray);
        }

        //Third Party Libraries...
        if(this.getThirdPartyLibraries() != null &&
                !this.getThirdPartyLibraries().isEmpty())
        {
            JSONArray jsonArray = new JSONArray();

            for(ThirdPartyLibrary thirdPartyLibrary : this.getThirdPartyLibraries())
            {
                jsonArray.put(thirdPartyLibrary.toJsonObject());
            }

            returnVal.put(JSONMapping.THIRD_PARTY_LIBRARIES, jsonArray);
        }

        //User Fields...
        if(this.getUserFields() != null && !this.getUserFields().isEmpty())
        {
            JSONArray jsonArray = new JSONArray();

            for(Field field : this.getUserFields())
            {
                jsonArray.put(field.toJsonObject());
            }

            returnVal.put(JSONMapping.USER_FIELDS, jsonArray);
        }

        //Route Fields...
        if(this.getRouteFields() != null && !this.getRouteFields().isEmpty())
        {
            JSONArray fieldsArr = new JSONArray();
            for(Field toAdd :this.getRouteFields())
            {
                fieldsArr.put(toAdd.toJsonObject());
            }

            returnVal.put(JSONMapping.ROUTE_FIELDS, fieldsArr);
        }

        //Global Fields...
        if(this.getGlobalFields() != null && !this.getGlobalFields().isEmpty())
        {
            JSONArray fieldsArr = new JSONArray();
            for(Field toAdd :this.getGlobalFields())
            {
                fieldsArr.put(toAdd.toJsonObject());
            }

            returnVal.put(JSONMapping.GLOBAL_FIELDS, fieldsArr);
        }
        
        return returnVal;
    }
@Override
    public JSONObject toJsonObject() throws JSONException {

        JSONObject returnVal = new JSONObject();

        //Template Name...
        if(this.getTemplateName() != null)
        {
            returnVal.put(JSONMapping.TEMPLATE_NAME,
                    this.getTemplateName());
        }

        //Template Description...
        if(this.getTemplateDescription() != null)
        {
            returnVal.put(JSONMapping.TEMPLATE_DESCRIPTION,
                    this.getTemplateDescription());
        }

        //Template Comment...
        if(this.getTemplateComment() != null)
        {
            returnVal.put(JSONMapping.TEMPLATE_COMMENT,
                    this.getTemplateComment());
        }

        //Forms and Fields...
        if(this.getFormsAndFields() != null && !this.getFormsAndFields().isEmpty())
        {
            JSONArray jsonArray = new JSONArray();

            for(Form form : this.getFormsAndFields())
            {
                jsonArray.put(form.toJsonObject());
            }

            returnVal.put(JSONMapping.FORMS_AND_FIELDS, jsonArray);
        }

        //User Queries...
        if(this.getUserQueries() != null && !this.getUserQueries().isEmpty())
        {
            JSONArray jsonArray = new JSONArray();

            for(UserQuery userQuery : this.getUserQueries())
            {
                jsonArray.put(userQuery.toJsonObject());
            }

            returnVal.put(JSONMapping.USER_QUERIES, jsonArray);
        }

        //Flows...
        if(this.getFlows() != null && !this.getFlows().isEmpty())
        {
            JSONArray jsonArray = new JSONArray();

            for(Flow flow : this.getFlows())
            {
                jsonArray.put(flow.toJsonObject());
            }

            returnVal.put(JSONMapping.FLOWS, jsonArray);
        }

        //Third Party Libraries...
        if(this.getThirdPartyLibraries() != null &&
                !this.getThirdPartyLibraries().isEmpty())
        {
            JSONArray jsonArray = new JSONArray();

            for(ThirdPartyLibrary thirdPartyLibrary : this.getThirdPartyLibraries())
            {
                jsonArray.put(thirdPartyLibrary.toJsonObject());
            }

            returnVal.put(JSONMapping.THIRD_PARTY_LIBRARIES, jsonArray);
        }

        //User Fields...
        if(this.getUserFields() != null && !this.getUserFields().isEmpty())
        {
            JSONArray jsonArray = new JSONArray();

            for(Field field : this.getUserFields())
            {
                jsonArray.put(field.toJsonObject());
            }

            returnVal.put(JSONMapping.USER_FIELDS, jsonArray);
        }

        //Route Fields...
        if(this.getRouteFields() != null && !this.getRouteFields().isEmpty())
        {
            JSONArray fieldsArr = new JSONArray();
            for(Field toAdd :this.getRouteFields())
            {
                fieldsArr.put(toAdd.toJsonObject());
            }

            returnVal.put(JSONMapping.ROUTE_FIELDS, fieldsArr);
        }

        //Global Fields...
        if(this.getGlobalFields() != null && !this.getGlobalFields().isEmpty())
        {
            JSONArray fieldsArr = new JSONArray();
            for(Field toAdd :this.getGlobalFields())
            {
                fieldsArr.put(toAdd.toJsonObject());
            }

            returnVal.put(JSONMapping.GLOBAL_FIELDS, fieldsArr);
        }
        
        return returnVal;
    }
Conversion to {@code JSONObject} from Java Object.

@return {@code JSONObject} representation of {@code FluidTemplate}
@throws JSONException If there is a problem with the JSON Body.