public static Value jsonValueToJCRValue ( Object value , ValueFactory valueFactory ) { if ( value == null ) { return null ; } // try the datatypes that can be handled by Jettison if ( value instanceof Integer || value instanceof Long ) { return valueFactory . createValue ( ( ( Number ) value ) . longValue ( ) ) ; } else if ( value instanceof Double || value instanceof Float ) { return valueFactory . createValue ( ( ( Number ) value ) . doubleValue ( ) ) ; } else if ( value instanceof Boolean ) { return valueFactory . createValue ( ( Boolean ) value ) ; } // try to convert to a date String valueString = value . toString ( ) ; for ( DateFormat dateFormat : ISO8601_DATE_PARSERS ) { try { Date date = dateFormat . parse ( valueString ) ; return valueFactory . createValue ( date ) ; } catch ( ParseException e ) { // ignore } catch ( ValueFormatException e ) { // ignore } } // default to a string return valueFactory . createValue ( valueString ) ; }
Converts an object value coming from a JSON object to a JCR value by attempting to convert it to a valid data type .