@Test public void jsToBigNumber_NativeJavaObject_Double() throws Exception { assertEquals( 1.0, JavaScriptUtils.jsToBigNumber( getDoubleValue(), JAVA_OBJECT ).doubleValue(), 1e-6 ); }
public static BigDecimal jsToBigNumber( Object value, String classType ) { if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeNumber" ) ) { Number nb = Context.toNumber( value ); return new BigDecimal( nb.doubleValue() ); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) { try { return (BigDecimal) Context.jsToJava( value, BigDecimal.class ); } catch ( Exception e ) { try { Value v = (Value) Context.jsToJava( value, Value.class ); if ( !v.isNull() ) { return v.getBigNumber(); } else { return null; } } catch ( Exception e2 ) { String string = (String) Context.jsToJava( value, String.class ); return new BigDecimal( string ); } } } else if ( classType.equalsIgnoreCase( "java.lang.Byte" ) ) { return new BigDecimal( ( (Byte) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Short" ) ) { return new BigDecimal( ( (Short) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Integer" ) ) { return new BigDecimal( ( (Integer) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Long" ) ) { return new BigDecimal( ( (Long) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Double" ) ) { return new BigDecimal( ( (Double) value ).doubleValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.String" ) ) { return new BigDecimal( ( new Long( (String) value ) ).longValue() ); } else { throw new RuntimeException( "JavaScript conversion to BigNumber not implemented for " + classType ); } }
JavaScriptUtils { public static BigDecimal jsToBigNumber( Object value, String classType ) { if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeNumber" ) ) { Number nb = Context.toNumber( value ); return new BigDecimal( nb.doubleValue() ); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) { try { return (BigDecimal) Context.jsToJava( value, BigDecimal.class ); } catch ( Exception e ) { try { Value v = (Value) Context.jsToJava( value, Value.class ); if ( !v.isNull() ) { return v.getBigNumber(); } else { return null; } } catch ( Exception e2 ) { String string = (String) Context.jsToJava( value, String.class ); return new BigDecimal( string ); } } } else if ( classType.equalsIgnoreCase( "java.lang.Byte" ) ) { return new BigDecimal( ( (Byte) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Short" ) ) { return new BigDecimal( ( (Short) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Integer" ) ) { return new BigDecimal( ( (Integer) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Long" ) ) { return new BigDecimal( ( (Long) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Double" ) ) { return new BigDecimal( ( (Double) value ).doubleValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.String" ) ) { return new BigDecimal( ( new Long( (String) value ) ).longValue() ); } else { throw new RuntimeException( "JavaScript conversion to BigNumber not implemented for " + classType ); } } }
JavaScriptUtils { public static BigDecimal jsToBigNumber( Object value, String classType ) { if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeNumber" ) ) { Number nb = Context.toNumber( value ); return new BigDecimal( nb.doubleValue() ); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) { try { return (BigDecimal) Context.jsToJava( value, BigDecimal.class ); } catch ( Exception e ) { try { Value v = (Value) Context.jsToJava( value, Value.class ); if ( !v.isNull() ) { return v.getBigNumber(); } else { return null; } } catch ( Exception e2 ) { String string = (String) Context.jsToJava( value, String.class ); return new BigDecimal( string ); } } } else if ( classType.equalsIgnoreCase( "java.lang.Byte" ) ) { return new BigDecimal( ( (Byte) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Short" ) ) { return new BigDecimal( ( (Short) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Integer" ) ) { return new BigDecimal( ( (Integer) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Long" ) ) { return new BigDecimal( ( (Long) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Double" ) ) { return new BigDecimal( ( (Double) value ).doubleValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.String" ) ) { return new BigDecimal( ( new Long( (String) value ) ).longValue() ); } else { throw new RuntimeException( "JavaScript conversion to BigNumber not implemented for " + classType ); } }  }
JavaScriptUtils { public static BigDecimal jsToBigNumber( Object value, String classType ) { if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeNumber" ) ) { Number nb = Context.toNumber( value ); return new BigDecimal( nb.doubleValue() ); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) { try { return (BigDecimal) Context.jsToJava( value, BigDecimal.class ); } catch ( Exception e ) { try { Value v = (Value) Context.jsToJava( value, Value.class ); if ( !v.isNull() ) { return v.getBigNumber(); } else { return null; } } catch ( Exception e2 ) { String string = (String) Context.jsToJava( value, String.class ); return new BigDecimal( string ); } } } else if ( classType.equalsIgnoreCase( "java.lang.Byte" ) ) { return new BigDecimal( ( (Byte) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Short" ) ) { return new BigDecimal( ( (Short) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Integer" ) ) { return new BigDecimal( ( (Integer) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Long" ) ) { return new BigDecimal( ( (Long) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Double" ) ) { return new BigDecimal( ( (Double) value ).doubleValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.String" ) ) { return new BigDecimal( ( new Long( (String) value ) ).longValue() ); } else { throw new RuntimeException( "JavaScript conversion to BigNumber not implemented for " + classType ); } }  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 BigDecimal jsToBigNumber( Object value, String classType ) { if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeNumber" ) ) { Number nb = Context.toNumber( value ); return new BigDecimal( nb.doubleValue() ); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) { try { return (BigDecimal) Context.jsToJava( value, BigDecimal.class ); } catch ( Exception e ) { try { Value v = (Value) Context.jsToJava( value, Value.class ); if ( !v.isNull() ) { return v.getBigNumber(); } else { return null; } } catch ( Exception e2 ) { String string = (String) Context.jsToJava( value, String.class ); return new BigDecimal( string ); } } } else if ( classType.equalsIgnoreCase( "java.lang.Byte" ) ) { return new BigDecimal( ( (Byte) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Short" ) ) { return new BigDecimal( ( (Short) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Integer" ) ) { return new BigDecimal( ( (Integer) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Long" ) ) { return new BigDecimal( ( (Long) value ).longValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.Double" ) ) { return new BigDecimal( ( (Double) value ).doubleValue() ); } else if ( classType.equalsIgnoreCase( "java.lang.String" ) ) { return new BigDecimal( ( new Long( (String) value ) ).longValue() ); } else { throw new RuntimeException( "JavaScript conversion to BigNumber not implemented for " + classType ); } }  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 );  }