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 目标对象
|
* @return 目标对象
|
||||||
*/
|
*/
|
||||||
public static <T> T copyProperties(Object source, Class<T> tClass) {
|
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());
|
copyProperties(source, target, CopyOptions.create());
|
||||||
return target;
|
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;
|
return result;
|
||||||
|
@ -58,7 +58,8 @@ public abstract class AbstractConverter<T> implements Converter<T>, Serializable
|
|||||||
T result = convertInternal(value);
|
T result = convertInternal(value);
|
||||||
return ((null == result) ? defaultValue : result);
|
return ((null == result) ? defaultValue : result);
|
||||||
} else {
|
} 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>
|
* <p>
|
||||||
* Data URI的格式规范:
|
* Data URI的格式规范:
|
||||||
* <pre>
|
* <pre>
|
||||||
* data:[<mime type>][;charset=<charset>][;<encoding>],<encoded data>
|
* data:[<mime type>][;charset=<charset>][;<encoding>],<encoded data>
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param mimeType 可选项(null表示无),数据类型(image/png、text/plain等)
|
* @param mimeType 可选项(null表示无),数据类型(image/png、text/plain等)
|
||||||
* @param encoding 数据编码方式(US-ASCII,BASE64等)
|
* @param encoding 数据编码方式(US-ASCII,BASE64等)
|
||||||
* @param data 编码后的数据
|
* @param data 编码后的数据
|
||||||
* @return Data URI字符串
|
* @return Data URI字符串
|
||||||
* @since 5.3.6
|
* @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);
|
return getDataUri(mimeType, null, encoding, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -803,25 +803,25 @@ public class URLUtil {
|
|||||||
* <p>
|
* <p>
|
||||||
* Data URI的格式规范:
|
* Data URI的格式规范:
|
||||||
* <pre>
|
* <pre>
|
||||||
* data:[<mime type>][;charset=<charset>][;<encoding>],<encoded data>
|
* data:[<mime type>][;charset=<charset>][;<encoding>],<encoded data>
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param mimeType 可选项(null表示无),数据类型(image/png、text/plain等)
|
* @param mimeType 可选项(null表示无),数据类型(image/png、text/plain等)
|
||||||
* @param charset 可选项(null表示无),源文本的字符集编码方式
|
* @param charset 可选项(null表示无),源文本的字符集编码方式
|
||||||
* @param encoding 数据编码方式(US-ASCII,BASE64等)
|
* @param encoding 数据编码方式(US-ASCII,BASE64等)
|
||||||
* @param data 编码后的数据
|
* @param data 编码后的数据
|
||||||
* @return Data URI字符串
|
* @return Data URI字符串
|
||||||
* @since 5.3.6
|
* @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:");
|
final StringBuilder builder = StrUtil.builder("data:");
|
||||||
if(StrUtil.isNotBlank(mimeType)){
|
if (StrUtil.isNotBlank(mimeType)) {
|
||||||
builder.append(mimeType);
|
builder.append(mimeType);
|
||||||
}
|
}
|
||||||
if(null != charset){
|
if (null != charset) {
|
||||||
builder.append(";charset=").append(charset.name());
|
builder.append(";charset=").append(charset.name());
|
||||||
}
|
}
|
||||||
if(StrUtil.isNotBlank(encoding)){
|
if (StrUtil.isNotBlank(encoding)) {
|
||||||
builder.append(';').append(encoding);
|
builder.append(';').append(encoding);
|
||||||
}
|
}
|
||||||
builder.append(',').append(data);
|
builder.append(',').append(data);
|
||||||
|
@ -237,6 +237,7 @@ public class BeanUtilTest {
|
|||||||
person.setOpenid("11213232");
|
person.setOpenid("11213232");
|
||||||
person.setName("测试A11");
|
person.setName("测试A11");
|
||||||
person.setSubName("sub名字");
|
person.setSubName("sub名字");
|
||||||
|
|
||||||
SubPerson person1 = BeanUtil.copyProperties(person, SubPerson.class);
|
SubPerson person1 = BeanUtil.copyProperties(person, SubPerson.class);
|
||||||
Assert.assertEquals(14, person1.getAge());
|
Assert.assertEquals(14, person1.getAge());
|
||||||
Assert.assertEquals("11213232", person1.getOpenid());
|
Assert.assertEquals("11213232", person1.getOpenid());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user