@ 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 ) ; } }
Converts a JSON array or a JSON object to a XML document .