public Policy createPolicyFromJsonString ( String jsonString ) { if ( jsonString == null ) { throw new IllegalArgumentException ( "JSON string cannot be null" ) ; } JsonNode policyNode ; JsonNode idNode ; JsonNode statementsNode ; Policy policy = new Policy ( ) ; List < Statement > statements = new LinkedList < Statement > ( ) ; try { policyNode = Jackson . jsonNodeOf ( jsonString ) ; idNode = policyNode . get ( JsonDocumentFields . POLICY_ID ) ; if ( isNotNull ( idNode ) ) { policy . setId ( idNode . asText ( ) ) ; } statementsNode = policyNode . get ( JsonDocumentFields . STATEMENT ) ; if ( isNotNull ( statementsNode ) ) { if ( statementsNode . isObject ( ) ) { statements . add ( statementOf ( statementsNode ) ) ; } else if ( statementsNode . isArray ( ) ) { for ( JsonNode statementNode : statementsNode ) { statements . add ( statementOf ( statementNode ) ) ; } } } } catch ( Exception e ) { String message = "Unable to generate policy object fron JSON string " + e . getMessage ( ) ; throw new IllegalArgumentException ( message , e ) ; } policy . setStatements ( statements ) ; return policy ; }
Converts the specified JSON string to an AWS policy object .