@Test public void testConvertJsonArrayWithRootTagNameToXmlElements() { Map<String, String> result = converter.execute( "[{\"name1\":\"value1\"},{\"name2\":\"value2\"}]", "false", "false", "items", "item", "", "", "", "", ","); assertNotNull(result); assertNotNull(result.get(RETURN_RESULT)); assertEquals(result.get(RETURN_CODE), SUCCESS); assertEquals(result.get(RETURN_RESULT), "<items><item><name1>value1</name1></item><item><name2>value2</name2></item></items>"); }
@Action(name = "Convert JSON to XML", outputs = { @Output(RETURN_RESULT), @Output(RETURN_CODE) }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = SUCCESS), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = FAILURE) }) public Map<String, String> execute( @Param(value = JSON, required = true) String json, @Param(value = PRETTY_PRINT) String prettyPrint, @Param(value = SHOW_XML_DECLARATION) String showXmlDeclaration, @Param(value = ROOT_TAG_NAME) String rootTagName, @Param(value = DEFAULT_JSON_ARRAY_ITEM_NAME) String defaultJsonArrayItemName, @Param(value = NAMESPACES_PREFIXES) String namespacesPrefixes, @Param(value = NAMESPACES_URIS) String namespacesUris, @Param(value = JSON_ARRAYS_NAMES) String jsonArraysNames, @Param(value = JSON_ARRAYS_ITEM_NAMES) String jsonArraysItemNames, @Param(value = DELIMITER) String delimiter) { try { showXmlDeclaration = StringUtils.defaultIfEmpty(showXmlDeclaration, TRUE); prettyPrint = StringUtils.defaultIfEmpty(prettyPrint, TRUE); ValidateUtils.validateInputs(prettyPrint, showXmlDeclaration); final ConvertJsonToXmlInputs inputs = new ConvertJsonToXmlInputs.ConvertJsonToXmlInputsBuilder() .withJson(json) .withPrettyPrint(Boolean.parseBoolean(prettyPrint)) .withShowXmlDeclaration(Boolean.parseBoolean(showXmlDeclaration)) .withRootTagName(rootTagName) .withDefaultJsonArrayItemName(defaultJsonArrayItemName) .withNamespaces(namespacesUris, namespacesPrefixes, delimiter) .withJsonArraysNames(jsonArraysNames, jsonArraysItemNames, delimiter) .build(); final ConvertJsonToXmlService converter = new ConvertJsonToXmlService(); converter.setNamespaces(inputs.getNamespaces()); converter.setJsonArrayItemNames(inputs.getArraysItemNames()); converter.setJsonArrayItemName(inputs.getDefaultJsonArrayItemName()); final String xml = converter.convertToXmlString(inputs); return getSuccessResultsMap(xml); } catch (Exception e) { return getFailureResultsMap(e); } }
ConvertJsonToXml { @Action(name = "Convert JSON to XML", outputs = { @Output(RETURN_RESULT), @Output(RETURN_CODE) }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = SUCCESS), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = FAILURE) }) public Map<String, String> execute( @Param(value = JSON, required = true) String json, @Param(value = PRETTY_PRINT) String prettyPrint, @Param(value = SHOW_XML_DECLARATION) String showXmlDeclaration, @Param(value = ROOT_TAG_NAME) String rootTagName, @Param(value = DEFAULT_JSON_ARRAY_ITEM_NAME) String defaultJsonArrayItemName, @Param(value = NAMESPACES_PREFIXES) String namespacesPrefixes, @Param(value = NAMESPACES_URIS) String namespacesUris, @Param(value = JSON_ARRAYS_NAMES) String jsonArraysNames, @Param(value = JSON_ARRAYS_ITEM_NAMES) String jsonArraysItemNames, @Param(value = DELIMITER) String delimiter) { try { showXmlDeclaration = StringUtils.defaultIfEmpty(showXmlDeclaration, TRUE); prettyPrint = StringUtils.defaultIfEmpty(prettyPrint, TRUE); ValidateUtils.validateInputs(prettyPrint, showXmlDeclaration); final ConvertJsonToXmlInputs inputs = new ConvertJsonToXmlInputs.ConvertJsonToXmlInputsBuilder() .withJson(json) .withPrettyPrint(Boolean.parseBoolean(prettyPrint)) .withShowXmlDeclaration(Boolean.parseBoolean(showXmlDeclaration)) .withRootTagName(rootTagName) .withDefaultJsonArrayItemName(defaultJsonArrayItemName) .withNamespaces(namespacesUris, namespacesPrefixes, delimiter) .withJsonArraysNames(jsonArraysNames, jsonArraysItemNames, delimiter) .build(); final ConvertJsonToXmlService converter = new ConvertJsonToXmlService(); converter.setNamespaces(inputs.getNamespaces()); converter.setJsonArrayItemNames(inputs.getArraysItemNames()); converter.setJsonArrayItemName(inputs.getDefaultJsonArrayItemName()); final String xml = converter.convertToXmlString(inputs); return getSuccessResultsMap(xml); } catch (Exception e) { return getFailureResultsMap(e); } } }
ConvertJsonToXml { @Action(name = "Convert JSON to XML", outputs = { @Output(RETURN_RESULT), @Output(RETURN_CODE) }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = SUCCESS), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = FAILURE) }) public Map<String, String> execute( @Param(value = JSON, required = true) String json, @Param(value = PRETTY_PRINT) String prettyPrint, @Param(value = SHOW_XML_DECLARATION) String showXmlDeclaration, @Param(value = ROOT_TAG_NAME) String rootTagName, @Param(value = DEFAULT_JSON_ARRAY_ITEM_NAME) String defaultJsonArrayItemName, @Param(value = NAMESPACES_PREFIXES) String namespacesPrefixes, @Param(value = NAMESPACES_URIS) String namespacesUris, @Param(value = JSON_ARRAYS_NAMES) String jsonArraysNames, @Param(value = JSON_ARRAYS_ITEM_NAMES) String jsonArraysItemNames, @Param(value = DELIMITER) String delimiter) { try { showXmlDeclaration = StringUtils.defaultIfEmpty(showXmlDeclaration, TRUE); prettyPrint = StringUtils.defaultIfEmpty(prettyPrint, TRUE); ValidateUtils.validateInputs(prettyPrint, showXmlDeclaration); final ConvertJsonToXmlInputs inputs = new ConvertJsonToXmlInputs.ConvertJsonToXmlInputsBuilder() .withJson(json) .withPrettyPrint(Boolean.parseBoolean(prettyPrint)) .withShowXmlDeclaration(Boolean.parseBoolean(showXmlDeclaration)) .withRootTagName(rootTagName) .withDefaultJsonArrayItemName(defaultJsonArrayItemName) .withNamespaces(namespacesUris, namespacesPrefixes, delimiter) .withJsonArraysNames(jsonArraysNames, jsonArraysItemNames, delimiter) .build(); final ConvertJsonToXmlService converter = new ConvertJsonToXmlService(); converter.setNamespaces(inputs.getNamespaces()); converter.setJsonArrayItemNames(inputs.getArraysItemNames()); converter.setJsonArrayItemName(inputs.getDefaultJsonArrayItemName()); final String xml = converter.convertToXmlString(inputs); return getSuccessResultsMap(xml); } catch (Exception e) { return getFailureResultsMap(e); } }  }
ConvertJsonToXml { @Action(name = "Convert JSON to XML", outputs = { @Output(RETURN_RESULT), @Output(RETURN_CODE) }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = SUCCESS), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = FAILURE) }) public Map<String, String> execute( @Param(value = JSON, required = true) String json, @Param(value = PRETTY_PRINT) String prettyPrint, @Param(value = SHOW_XML_DECLARATION) String showXmlDeclaration, @Param(value = ROOT_TAG_NAME) String rootTagName, @Param(value = DEFAULT_JSON_ARRAY_ITEM_NAME) String defaultJsonArrayItemName, @Param(value = NAMESPACES_PREFIXES) String namespacesPrefixes, @Param(value = NAMESPACES_URIS) String namespacesUris, @Param(value = JSON_ARRAYS_NAMES) String jsonArraysNames, @Param(value = JSON_ARRAYS_ITEM_NAMES) String jsonArraysItemNames, @Param(value = DELIMITER) String delimiter) { try { showXmlDeclaration = StringUtils.defaultIfEmpty(showXmlDeclaration, TRUE); prettyPrint = StringUtils.defaultIfEmpty(prettyPrint, TRUE); ValidateUtils.validateInputs(prettyPrint, showXmlDeclaration); final ConvertJsonToXmlInputs inputs = new ConvertJsonToXmlInputs.ConvertJsonToXmlInputsBuilder() .withJson(json) .withPrettyPrint(Boolean.parseBoolean(prettyPrint)) .withShowXmlDeclaration(Boolean.parseBoolean(showXmlDeclaration)) .withRootTagName(rootTagName) .withDefaultJsonArrayItemName(defaultJsonArrayItemName) .withNamespaces(namespacesUris, namespacesPrefixes, delimiter) .withJsonArraysNames(jsonArraysNames, jsonArraysItemNames, delimiter) .build(); final ConvertJsonToXmlService converter = new ConvertJsonToXmlService(); converter.setNamespaces(inputs.getNamespaces()); converter.setJsonArrayItemNames(inputs.getArraysItemNames()); converter.setJsonArrayItemName(inputs.getDefaultJsonArrayItemName()); final String xml = converter.convertToXmlString(inputs); return getSuccessResultsMap(xml); } catch (Exception e) { return getFailureResultsMap(e); } }  @Action(name = "Convert JSON to XML", outputs = { @Output(RETURN_RESULT), @Output(RETURN_CODE) }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = SUCCESS), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = FAILURE) }) Map<String, String> execute(
            @Param(value = JSON, required = true) String json,
            @Param(value = PRETTY_PRINT) String prettyPrint,
            @Param(value = SHOW_XML_DECLARATION) String showXmlDeclaration,
            @Param(value = ROOT_TAG_NAME) String rootTagName,
            @Param(value = DEFAULT_JSON_ARRAY_ITEM_NAME) String defaultJsonArrayItemName,
            @Param(value = NAMESPACES_PREFIXES) String namespacesPrefixes,
            @Param(value = NAMESPACES_URIS) String namespacesUris,
            @Param(value = JSON_ARRAYS_NAMES) String jsonArraysNames,
            @Param(value = JSON_ARRAYS_ITEM_NAMES) String jsonArraysItemNames,
            @Param(value = DELIMITER) String delimiter); }
ConvertJsonToXml { @Action(name = "Convert JSON to XML", outputs = { @Output(RETURN_RESULT), @Output(RETURN_CODE) }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = SUCCESS), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = FAILURE) }) public Map<String, String> execute( @Param(value = JSON, required = true) String json, @Param(value = PRETTY_PRINT) String prettyPrint, @Param(value = SHOW_XML_DECLARATION) String showXmlDeclaration, @Param(value = ROOT_TAG_NAME) String rootTagName, @Param(value = DEFAULT_JSON_ARRAY_ITEM_NAME) String defaultJsonArrayItemName, @Param(value = NAMESPACES_PREFIXES) String namespacesPrefixes, @Param(value = NAMESPACES_URIS) String namespacesUris, @Param(value = JSON_ARRAYS_NAMES) String jsonArraysNames, @Param(value = JSON_ARRAYS_ITEM_NAMES) String jsonArraysItemNames, @Param(value = DELIMITER) String delimiter) { try { showXmlDeclaration = StringUtils.defaultIfEmpty(showXmlDeclaration, TRUE); prettyPrint = StringUtils.defaultIfEmpty(prettyPrint, TRUE); ValidateUtils.validateInputs(prettyPrint, showXmlDeclaration); final ConvertJsonToXmlInputs inputs = new ConvertJsonToXmlInputs.ConvertJsonToXmlInputsBuilder() .withJson(json) .withPrettyPrint(Boolean.parseBoolean(prettyPrint)) .withShowXmlDeclaration(Boolean.parseBoolean(showXmlDeclaration)) .withRootTagName(rootTagName) .withDefaultJsonArrayItemName(defaultJsonArrayItemName) .withNamespaces(namespacesUris, namespacesPrefixes, delimiter) .withJsonArraysNames(jsonArraysNames, jsonArraysItemNames, delimiter) .build(); final ConvertJsonToXmlService converter = new ConvertJsonToXmlService(); converter.setNamespaces(inputs.getNamespaces()); converter.setJsonArrayItemNames(inputs.getArraysItemNames()); converter.setJsonArrayItemName(inputs.getDefaultJsonArrayItemName()); final String xml = converter.convertToXmlString(inputs); return getSuccessResultsMap(xml); } catch (Exception e) { return getFailureResultsMap(e); } }  @Action(name = "Convert JSON to XML", outputs = { @Output(RETURN_RESULT), @Output(RETURN_CODE) }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = SUCCESS), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = FAILURE) }) Map<String, String> execute(
            @Param(value = JSON, required = true) String json,
            @Param(value = PRETTY_PRINT) String prettyPrint,
            @Param(value = SHOW_XML_DECLARATION) String showXmlDeclaration,
            @Param(value = ROOT_TAG_NAME) String rootTagName,
            @Param(value = DEFAULT_JSON_ARRAY_ITEM_NAME) String defaultJsonArrayItemName,
            @Param(value = NAMESPACES_PREFIXES) String namespacesPrefixes,
            @Param(value = NAMESPACES_URIS) String namespacesUris,
            @Param(value = JSON_ARRAYS_NAMES) String jsonArraysNames,
            @Param(value = JSON_ARRAYS_ITEM_NAMES) String jsonArraysItemNames,
            @Param(value = DELIMITER) String delimiter);  }