@ Action ( name = "Convert XML to Json" , outputs = { @ Output ( NAMESPACES_PREFIXES ) , @ Output ( NAMESPACES_URIS ) , @ Output ( RETURN_RESULT ) , @ Output ( RETURN_CODE ) , @ Output ( EXCEPTION ) } , 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 = XML , required = true ) String xml , @ Param ( value = TEXT_ELEMENTS_NAME ) String textElementsName , @ Param ( value = INCLUDE_ROOT ) String includeRootElement , @ Param ( value = INCLUDE_ATTRIBUTES ) String includeAttributes , @ Param ( value = PRETTY_PRINT ) String prettyPrint , @ Param ( value = PARSING_FEATURES ) String parsingFeatures ) { try { includeRootElement = defaultIfEmpty ( includeRootElement , TRUE ) ; includeAttributes = defaultIfEmpty ( includeAttributes , TRUE ) ; prettyPrint = defaultIfEmpty ( prettyPrint , TRUE ) ; ValidateUtils . validateInputs ( includeRootElement , includeAttributes , prettyPrint ) ; final ConvertXmlToJsonInputs inputs = new ConvertXmlToJsonInputs . ConvertXmlToJsonInputsBuilder ( ) . withXml ( xml ) . withTextElementsName ( textElementsName ) . withIncludeRootElement ( Boolean . parseBoolean ( includeRootElement ) ) . withIncludeAttributes ( Boolean . parseBoolean ( includeAttributes ) ) . withPrettyPrint ( Boolean . parseBoolean ( prettyPrint ) ) . withParsingFeatures ( parsingFeatures ) . build ( ) ; final ConvertXmlToJsonService converter = new ConvertXmlToJsonService ( ) ; final String json = converter . convertToJsonString ( inputs ) ; final Map < String , String > result = getSuccessResultsMap ( json ) ; result . put ( NAMESPACES_PREFIXES , converter . getNamespacesPrefixes ( ) ) ; result . put ( NAMESPACES_URIS , converter . getNamespacesUris ( ) ) ; return result ; } catch ( Exception e ) { final Map < String , String > result = getFailureResultsMap ( e ) ; result . put ( NAMESPACES_PREFIXES , EMPTY ) ; result . put ( NAMESPACES_URIS , EMPTY ) ; return result ; } }
Converts a XML document to a JSON array or a JSON object .