mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix bean
This commit is contained in:
parent
e9400766a9
commit
df58ad5eff
@ -614,7 +614,7 @@ public class BeanUtil {
|
||||
* @return 目标对象
|
||||
*/
|
||||
public static <T> T copyProperties(Object source, Class<T> tClass) {
|
||||
T target = ReflectUtil.newInstance(tClass);
|
||||
T target = ReflectUtil.newInstanceIfPossible(tClass);
|
||||
copyProperties(source, target, CopyOptions.create());
|
||||
return target;
|
||||
}
|
||||
|
@ -57,7 +57,10 @@ public class BeanValueProvider implements ValueProvider<String> {
|
||||
}
|
||||
|
||||
// 尝试将结果转换为目标类型,如果转换失败,返回原类型。
|
||||
result = Convert.convertWithCheck(valueType,result, result, ignoreError);
|
||||
final Object convertValue = Convert.convertWithCheck(valueType,result, null, ignoreError);
|
||||
if(null != convertValue){
|
||||
result = convertValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -58,7 +58,8 @@ public abstract class AbstractConverter<T> implements Converter<T>, Serializable
|
||||
T result = convertInternal(value);
|
||||
return ((null == result) ? defaultValue : result);
|
||||
} else {
|
||||
throw new IllegalArgumentException(StrUtil.format("Default value [{}] is not the instance of [{}]", defaultValue, targetType));
|
||||
throw new IllegalArgumentException(
|
||||
StrUtil.format("Default value [{}]({}) is not the instance of [{}]", defaultValue, defaultValue.getClass(), targetType));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -783,16 +783,16 @@ public class URLUtil {
|
||||
* <p>
|
||||
* Data URI的格式规范:
|
||||
* <pre>
|
||||
* data:[<mime type>][;charset=<charset>][;<encoding>],<encoded data>
|
||||
* data:[<mime type>][;charset=<charset>][;<encoding>],<encoded data>
|
||||
* </pre>
|
||||
*
|
||||
* @param mimeType 可选项(null表示无),数据类型(image/png、text/plain等)
|
||||
* @param encoding 数据编码方式(US-ASCII,BASE64等)
|
||||
* @param data 编码后的数据
|
||||
* @param data 编码后的数据
|
||||
* @return Data URI字符串
|
||||
* @since 5.3.6
|
||||
*/
|
||||
public static String getDataUri(String mimeType, String encoding, String data){
|
||||
public static String getDataUri(String mimeType, String encoding, String data) {
|
||||
return getDataUri(mimeType, null, encoding, data);
|
||||
}
|
||||
|
||||
@ -803,25 +803,25 @@ public class URLUtil {
|
||||
* <p>
|
||||
* Data URI的格式规范:
|
||||
* <pre>
|
||||
* data:[<mime type>][;charset=<charset>][;<encoding>],<encoded data>
|
||||
* data:[<mime type>][;charset=<charset>][;<encoding>],<encoded data>
|
||||
* </pre>
|
||||
*
|
||||
* @param mimeType 可选项(null表示无),数据类型(image/png、text/plain等)
|
||||
* @param charset 可选项(null表示无),源文本的字符集编码方式
|
||||
* @param charset 可选项(null表示无),源文本的字符集编码方式
|
||||
* @param encoding 数据编码方式(US-ASCII,BASE64等)
|
||||
* @param data 编码后的数据
|
||||
* @param data 编码后的数据
|
||||
* @return Data URI字符串
|
||||
* @since 5.3.6
|
||||
*/
|
||||
public static String getDataUri(String mimeType, Charset charset, String encoding, String data){
|
||||
public static String getDataUri(String mimeType, Charset charset, String encoding, String data) {
|
||||
final StringBuilder builder = StrUtil.builder("data:");
|
||||
if(StrUtil.isNotBlank(mimeType)){
|
||||
if (StrUtil.isNotBlank(mimeType)) {
|
||||
builder.append(mimeType);
|
||||
}
|
||||
if(null != charset){
|
||||
if (null != charset) {
|
||||
builder.append(";charset=").append(charset.name());
|
||||
}
|
||||
if(StrUtil.isNotBlank(encoding)){
|
||||
if (StrUtil.isNotBlank(encoding)) {
|
||||
builder.append(';').append(encoding);
|
||||
}
|
||||
builder.append(',').append(data);
|
||||
|
@ -237,6 +237,7 @@ public class BeanUtilTest {
|
||||
person.setOpenid("11213232");
|
||||
person.setName("测试A11");
|
||||
person.setSubName("sub名字");
|
||||
|
||||
SubPerson person1 = BeanUtil.copyProperties(person, SubPerson.class);
|
||||
Assert.assertEquals(14, person1.getAge());
|
||||
Assert.assertEquals("11213232", person1.getOpenid());
|
||||
|
Loading…
x
Reference in New Issue
Block a user