class ConvertJSONToXML extends AbstractProcessor {

    protected byte[] convertJsonToXMLBytes(InputStream jsonInputStream, String jsonPathExpression, String attributeMark, String nameSpace, String contentKeyName, String encoding, String elementName) throws IOException {

        try(InputStreamReader isr = new InputStreamReader(jsonInputStream, StandardCharsets.UTF_8);
            BufferedReader br = new BufferedReader(isr)){

            XMLConverter xmlInstance = new XMLConverter();
            xmlInstance.setNameSpace(nameSpace);
            xmlInstance.setAttributeMark(attributeMark);
            if (contentKeyName != null) {
                xmlInstance.setDataTagName(contentKeyName);
            } else {
                xmlInstance.setDataTagName("");
            }

            if (jsonPathExpression == null) {
                Object json =new JSONTokener(br).nextValue();
                if(json instanceof JSONObject){
                    return xmlInstance.toBytes_p(json, elementName, encoding);
                } else if(json instanceof JSONArray){
                    return xmlInstance.toBytes_p(json, "list", encoding);
                }
                JSONObject jsonObject = new JSONObject(jsonInputStream);
                return xmlInstance.toBytes_p(jsonObject, elementName, encoding);
            } else {
                Object items = JsonPath.read(jsonInputStream, jsonPathExpression);
                Map<String, Object> map = new HashMap<>();
                map.put(elementName, items);
                JSONObject jsonObject = new JSONObject(map);
                if ((items instanceof net.minidev.json.JSONArray || items.getClass().isArray())) {
                    if (((List) items).size() == 0) {
                        map.put(elementName, "");
                        jsonObject = new JSONObject(map);
                    }
                    return xmlInstance.toBytes_p(jsonObject, "list", encoding);
                } else {
                    return xmlInstance.toBytes_p(jsonObject, null, encoding);
                }
            }
        }
    }

}