@Test public void convertFromJs_TypeBinary() throws Exception { byte[] bytes = new byte[] { 0, 1 }; Object converted = JavaScriptUtils.convertFromJs( bytes, ValueMetaInterface.TYPE_BINARY, "qwerty" ); assertThat( converted, is( instanceOf( byte[].class ) ) ); assertArrayEquals( bytes, (byte[]) converted ); }
public static Object convertFromJs( Object value, int type, String fieldName ) throws KettleValueException { String classType = value.getClass().getName(); switch ( type ) { case ValueMetaInterface.TYPE_NUMBER: return jsToNumber( value, classType ); case ValueMetaInterface.TYPE_INTEGER: return jsToInteger( value, value.getClass() ); case ValueMetaInterface.TYPE_STRING: return jsToString( value, classType ); case ValueMetaInterface.TYPE_DATE: return jsToDate( value, classType ); case ValueMetaInterface.TYPE_BOOLEAN: return value; case ValueMetaInterface.TYPE_BIGNUMBER: return jsToBigNumber( value, classType ); case ValueMetaInterface.TYPE_BINARY: { return Context.jsToJava( value, byte[].class ); } case ValueMetaInterface.TYPE_NONE: { throw new RuntimeException( "No data output data type was specified for new field [" + fieldName + "]" ); } default: return Context.jsToJava( value, Object.class ); } }
JavaScriptUtils { public static Object convertFromJs( Object value, int type, String fieldName ) throws KettleValueException { String classType = value.getClass().getName(); switch ( type ) { case ValueMetaInterface.TYPE_NUMBER: return jsToNumber( value, classType ); case ValueMetaInterface.TYPE_INTEGER: return jsToInteger( value, value.getClass() ); case ValueMetaInterface.TYPE_STRING: return jsToString( value, classType ); case ValueMetaInterface.TYPE_DATE: return jsToDate( value, classType ); case ValueMetaInterface.TYPE_BOOLEAN: return value; case ValueMetaInterface.TYPE_BIGNUMBER: return jsToBigNumber( value, classType ); case ValueMetaInterface.TYPE_BINARY: { return Context.jsToJava( value, byte[].class ); } case ValueMetaInterface.TYPE_NONE: { throw new RuntimeException( "No data output data type was specified for new field [" + fieldName + "]" ); } default: return Context.jsToJava( value, Object.class ); } } }
JavaScriptUtils { public static Object convertFromJs( Object value, int type, String fieldName ) throws KettleValueException { String classType = value.getClass().getName(); switch ( type ) { case ValueMetaInterface.TYPE_NUMBER: return jsToNumber( value, classType ); case ValueMetaInterface.TYPE_INTEGER: return jsToInteger( value, value.getClass() ); case ValueMetaInterface.TYPE_STRING: return jsToString( value, classType ); case ValueMetaInterface.TYPE_DATE: return jsToDate( value, classType ); case ValueMetaInterface.TYPE_BOOLEAN: return value; case ValueMetaInterface.TYPE_BIGNUMBER: return jsToBigNumber( value, classType ); case ValueMetaInterface.TYPE_BINARY: { return Context.jsToJava( value, byte[].class ); } case ValueMetaInterface.TYPE_NONE: { throw new RuntimeException( "No data output data type was specified for new field [" + fieldName + "]" ); } default: return Context.jsToJava( value, Object.class ); } }  }
JavaScriptUtils { public static Object convertFromJs( Object value, int type, String fieldName ) throws KettleValueException { String classType = value.getClass().getName(); switch ( type ) { case ValueMetaInterface.TYPE_NUMBER: return jsToNumber( value, classType ); case ValueMetaInterface.TYPE_INTEGER: return jsToInteger( value, value.getClass() ); case ValueMetaInterface.TYPE_STRING: return jsToString( value, classType ); case ValueMetaInterface.TYPE_DATE: return jsToDate( value, classType ); case ValueMetaInterface.TYPE_BOOLEAN: return value; case ValueMetaInterface.TYPE_BIGNUMBER: return jsToBigNumber( value, classType ); case ValueMetaInterface.TYPE_BINARY: { return Context.jsToJava( value, byte[].class ); } case ValueMetaInterface.TYPE_NONE: { throw new RuntimeException( "No data output data type was specified for new field [" + fieldName + "]" ); } default: return Context.jsToJava( value, Object.class ); } }  static Object convertFromJs( Object value, int type, String fieldName ); static Number jsToNumber( Object value, String classType ); static Long jsToInteger( Object value, Class<?> clazz ); static String jsToString( Object value, String classType ); static Date jsToDate( Object value, String classType ); static BigDecimal jsToBigNumber( Object value, String classType ); }
JavaScriptUtils { public static Object convertFromJs( Object value, int type, String fieldName ) throws KettleValueException { String classType = value.getClass().getName(); switch ( type ) { case ValueMetaInterface.TYPE_NUMBER: return jsToNumber( value, classType ); case ValueMetaInterface.TYPE_INTEGER: return jsToInteger( value, value.getClass() ); case ValueMetaInterface.TYPE_STRING: return jsToString( value, classType ); case ValueMetaInterface.TYPE_DATE: return jsToDate( value, classType ); case ValueMetaInterface.TYPE_BOOLEAN: return value; case ValueMetaInterface.TYPE_BIGNUMBER: return jsToBigNumber( value, classType ); case ValueMetaInterface.TYPE_BINARY: { return Context.jsToJava( value, byte[].class ); } case ValueMetaInterface.TYPE_NONE: { throw new RuntimeException( "No data output data type was specified for new field [" + fieldName + "]" ); } default: return Context.jsToJava( value, Object.class ); } }  static Object convertFromJs( Object value, int type, String fieldName ); static Number jsToNumber( Object value, String classType ); static Long jsToInteger( Object value, Class<?> clazz ); static String jsToString( Object value, String classType ); static Date jsToDate( Object value, String classType ); static BigDecimal jsToBigNumber( Object value, String classType );  }