本文整理了Java中org.apache.commons.beanutils.Converter.convert()
方法的一些代码示例,展示了Converter.convert()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Converter.convert()
方法的具体详情如下:
包路径:org.apache.commons.beanutils.Converter
类名称:Converter
方法名:convert
[英]Convert the specified input object into an output object of the specified type.
[中]将指定的输入对象转换为指定类型的输出对象。
代码示例来源:origin: commons-beanutils/commons-beanutils
/**
* 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);
}
代码示例来源:origin: wildfly/wildfly
/**
* 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);
}
代码示例来源:origin: alibaba/canal
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进行转化
}
}
代码示例来源:origin: commons-beanutils/commons-beanutils
/**
* 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));
}
}
代码示例来源:origin: wildfly/wildfly
/**
* 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));
}
}
代码示例来源:origin: commons-beanutils/commons-beanutils
/**
* 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));
}
代码示例来源:origin: wildfly/wildfly
/**
* 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));
}
代码示例来源:origin: pmd/pmd
@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);
}
代码示例来源:origin: DozerMapper/dozer
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);
}
}
代码示例来源:origin: commons-beanutils/commons-beanutils
/**
* <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;
}
}
代码示例来源:origin: commons-beanutils/commons-beanutils
log.trace(" Using converter " + converter);
converted = converter.convert(targetType, value);
log.trace(" Using converter " + converter);
converted = converter.convert(String.class, converted);
代码示例来源:origin: commons-beanutils/commons-beanutils
element = elementConverter.convert(String.class, element);
if (element != null) {
buffer.append(element);
代码示例来源:origin: commons-beanutils/commons-beanutils
Array.set(array, i, converter.convert(type, values[i]));
代码示例来源:origin: wildfly/wildfly
log.trace(" Using converter " + converter);
converted = converter.convert(targetType, value);
log.trace(" Using converter " + converter);
converted = converter.convert(String.class, converted);
代码示例来源:origin: wildfly/wildfly
Array.set(array, i, converter.convert(type, values[i]));
代码示例来源:origin: wildfly/wildfly
element = elementConverter.convert(String.class, element);
if (element != null) {
buffer.append(element);
代码示例来源:origin: wildfly/wildfly
/**
* <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;
}
}
代码示例来源:origin: commons-beanutils/commons-beanutils
element = elementConverter.convert(componentType, element);
Array.set(newArray, i, element);
代码示例来源:origin: wildfly/wildfly
element = elementConverter.convert(componentType, element);
Array.set(newArray, i, element);
代码示例来源:origin: jenkinsci/configuration-as-code-plugin
@Nonnull
@Override
public Object configure(CNode config, ConfigurationContext context) throws ConfiguratorException {
return Stapler.lookupConverter(target).convert(target, SecretSourceResolver.resolve(context, config.asScalar().toString()));
}
内容来源于网络,如有侵权,请联系作者删除!