/** * Convert the input object into an output object of the * specified type by delegating to the underlying {@link Converter} * implementation. * * @param <T> The result type of the conversion * @param type Data type to which this value should be converted * @param value The input value to be converted * @return The converted value. */ public <T> T convert(final Class<T> type, final Object value) { return converter.convert(type, value); }
/** * Convert the input object into an output object of the * specified type by delegating to the underlying {@link Converter} * implementation. * * @param <T> The result type of the conversion * @param type Data type to which this value should be converted * @param value The input value to be converted * @return The converted value. */ public <T> T convert(final Class<T> type, final Object value) { return converter.convert(type, value); }
public Object convert(Class type, Object value) { if (value == null) { if (useDefault) { return (defaultValue); } else { throw new ConversionException("No value specified"); } } if (value instanceof byte[]) { return (value); } // BLOB类型,canal直接存储为String("ISO-8859-1") if (value instanceof String) { try { return ((String) value).getBytes("ISO-8859-1"); } catch (Exception e) { throw new ConversionException(e); } } return converter.convert(type, value); // byteConvertor进行转化 } }
/** * Convert the specified value into a String. If the specified value * is an array, the first element (converted to a String) will be * returned. The registered {@link Converter} for the * <code>java.lang.String</code> class will be used, which allows * applications to customize Object->String conversions (the default * implementation simply uses toString()). * * @param value Value to be converted (may be null) * @return The converted String value or null if value is null */ public String convert(Object value) { if (value == null) { return null; } else if (value.getClass().isArray()) { if (Array.getLength(value) < 1) { return (null); } value = Array.get(value, 0); if (value == null) { return null; } else { final Converter converter = lookup(String.class); return (converter.convert(String.class, value)); } } else { final Converter converter = lookup(String.class); return (converter.convert(String.class, value)); } }
/** * Convert the specified value into a String. If the specified value * is an array, the first element (converted to a String) will be * returned. The registered {@link Converter} for the * <code>java.lang.String</code> class will be used, which allows * applications to customize Object->String conversions (the default * implementation simply uses toString()). * * @param value Value to be converted (may be null) * @return The converted String value or null if value is null */ public String convert(Object value) { if (value == null) { return null; } else if (value.getClass().isArray()) { if (Array.getLength(value) < 1) { return (null); } value = Array.get(value, 0); if (value == null) { return null; } else { final Converter converter = lookup(String.class); return (converter.convert(String.class, value)); } } else { final Converter converter = lookup(String.class); return (converter.convert(String.class, value)); } }
/** * Convert the specified value to an object of the specified class (if * possible). Otherwise, return a String representation of the value. * * @param value Value to be converted (may be null) * @param clazz Java class to be converted to (must not be null) * @return The converted value * * @throws ConversionException if thrown by an underlying Converter */ public Object convert(final String value, final Class<?> clazz) { if (log.isDebugEnabled()) { log.debug("Convert string '" + value + "' to class '" + clazz.getName() + "'"); } Converter converter = lookup(clazz); if (converter == null) { converter = lookup(String.class); } if (log.isTraceEnabled()) { log.trace(" Using converter " + converter); } return (converter.convert(clazz, value)); }
/** * Convert the specified value to an object of the specified class (if * possible). Otherwise, return a String representation of the value. * * @param value Value to be converted (may be null) * @param clazz Java class to be converted to (must not be null) * @return The converted value * * @throws ConversionException if thrown by an underlying Converter */ public Object convert(final String value, final Class<?> clazz) { if (log.isDebugEnabled()) { log.debug("Convert string '" + value + "' to class '" + clazz.getName() + "'"); } Converter converter = lookup(clazz); if (converter == null) { converter = lookup(String.class); } if (log.isTraceEnabled()) { log.trace(" Using converter " + converter); } return (converter.convert(clazz, value)); }
@Override public void visit(SimpleBeanModelNode node, Element parent) { Element nodeElement = parent.getOwnerDocument().createElement(SCHEMA_NODE_ELEMENT); nodeElement.setAttribute(SCHEMA_NODE_CLASS_ATTRIBUTE, node.getNodeType().getCanonicalName()); for (Entry<String, Object> keyValue : node.getSettingsValues().entrySet()) { // I don't think the API is intended to be used like that // but ConvertUtils wouldn't use the convertToString methods // defined in the converters otherwise. // Even when a built-in converter is available, objects are // still converted with Object::toString which fucks up the // conversion... String value = (String) ConvertUtils.lookup(keyValue.getValue().getClass()).convert(String.class, keyValue.getValue()); if (value == null) { continue; } Element setting = parent.getOwnerDocument().createElement(SCHEMA_PROPERTY_ELEMENT); setting.setAttribute(SCHEMA_PROPERTY_NAME, keyValue.getKey()); setting.setAttribute(SCHEMA_PROPERTY_TYPE, node.getSettingsTypes().get(keyValue.getKey()).getCanonicalName()); setting.appendChild(parent.getOwnerDocument().createCDATASection(value)); nodeElement.appendChild(setting); } parent.appendChild(nodeElement); super.visit(node, nodeElement); }
public Object convert(Object srcFieldValue, Class destFieldClass, DateFormatContainer dateFormatContainer, String destFieldName, Object destObj) { if (srcFieldValue == null || destFieldClass == null || (srcFieldValue.equals("") && !destFieldClass.equals(String.class))) { return null; } Converter converter = getPrimitiveOrWrapperConverter(destFieldClass, dateFormatContainer, destFieldName, destObj); try { return converter.convert(destFieldClass, unwrapSrcFieldValue(srcFieldValue)); } catch (org.apache.commons.beanutils.ConversionException e) { throw new com.github.dozermapper.core.converters.ConversionException(e); } }
/** * <p>Convert the value to an object of the specified class (if * possible).</p> * * @param value Value to be converted (may be null) * @param type Class of the value to be converted to * @return The converted value * * @throws ConversionException if thrown by an underlying Converter * @since 1.8.0 */ protected Object convert(final Object value, final Class<?> type) { final Converter converter = getConvertUtils().lookup(type); if (converter != null) { log.trace(" USING CONVERTER " + converter); return converter.convert(type, value); } else { return value; } }
element = elementConverter.convert(String.class, element); if (element != null) { buffer.append(element);
Array.set(array, i, converter.convert(type, values[i]));
Array.set(array, i, converter.convert(type, values[i]));
element = elementConverter.convert(String.class, element); if (element != null) { buffer.append(element);
/** * <p>Convert the value to an object of the specified class (if * possible).</p> * * @param value Value to be converted (may be null) * @param type Class of the value to be converted to * @return The converted value * * @throws ConversionException if thrown by an underlying Converter * @since 1.8.0 */ protected Object convert(final Object value, final Class<?> type) { final Converter converter = getConvertUtils().lookup(type); if (converter != null) { log.trace(" USING CONVERTER " + converter); return converter.convert(type, value); } else { return value; } }
element = elementConverter.convert(componentType, element); Array.set(newArray, i, element);
element = elementConverter.convert(componentType, element); Array.set(newArray, i, element);
@Nonnull @Override public Object configure(CNode config, ConfigurationContext context) throws ConfiguratorException { return Stapler.lookupConverter(target).convert(target, SecretSourceResolver.resolve(context, config.asScalar().toString())); }