public static SassValue convertToSassValue ( Object value ) { if ( null == value ) { return SassNull . SINGLETON ; } if ( value instanceof SassValue ) { return ( SassValue ) value ; } Class cls = value . getClass ( ) ; if ( isaBoolean ( cls ) ) { return new SassBoolean ( ( Boolean ) value ) ; } if ( isaNumber ( cls ) ) { return new SassNumber ( ( ( Number ) value ) . doubleValue ( ) , "" ) ; } if ( isaString ( cls ) || isaCharacter ( cls ) ) { return new SassString ( value . toString ( ) ) ; } if ( value instanceof Collection ) { return new SassList ( ( ( Collection < ? > ) value ) . stream ( ) . map ( TypeUtils :: convertToSassValue ) . collect ( Collectors . toList ( ) ) ) ; } if ( value instanceof Map ) { return ( ( Map < ? , ? > ) value ) . entrySet ( ) . stream ( ) . collect ( Collectors . toMap ( entry -> entry . getKey ( ) . toString ( ) , entry -> TypeUtils . convertToSassValue ( entry . getValue ( ) ) , ( origin , duplicate ) -> origin , SassMap :: new ) ) ; } if ( value instanceof Throwable ) { Throwable throwable = ( Throwable ) value ; StringWriter stringWriter = new StringWriter ( ) ; PrintWriter printWriter = new PrintWriter ( stringWriter ) ; String message = throwable . getMessage ( ) ; if ( StringUtils . isNotEmpty ( message ) ) { printWriter . append ( message ) . append ( System . lineSeparator ( ) ) ; } throwable . printStackTrace ( printWriter ) ; return new SassError ( stringWriter . toString ( ) ) ; } return new SassError ( String . format ( "Could not convert object of type %s into a sass value" , value . getClass ( ) . toString ( ) ) ) ; }
Try to convert any java object into a responsible sass value .