mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix bugs
This commit is contained in:
parent
7c05a71159
commit
0cd79bcbfd
@ -16,6 +16,7 @@
|
|||||||
* 【core 】 Tree增加getParent方法,可以获取父节点,抽象Node接口
|
* 【core 】 Tree增加getParent方法,可以获取父节点,抽象Node接口
|
||||||
* 【core 】 增加社会信用代码工具CreditCodeUtil(pr#112@Gitee)
|
* 【core 】 增加社会信用代码工具CreditCodeUtil(pr#112@Gitee)
|
||||||
* 【core 】 ChineseDate增加构造重载,增加toStringNormal(issue#792@Github)
|
* 【core 】 ChineseDate增加构造重载,增加toStringNormal(issue#792@Github)
|
||||||
|
* 【core 】 BeanUtil.toBean增加重载(issue#797@Github)
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【core 】 修复TypeUtil无法获取泛型接口的泛型参数问题(issue#I1BRFI@Gitee)
|
* 【core 】 修复TypeUtil无法获取泛型接口的泛型参数问题(issue#I1BRFI@Gitee)
|
||||||
@ -23,6 +24,7 @@
|
|||||||
* 【core 】 修复BeanPath从Map取值为空的问题(issue#790@Github)
|
* 【core 】 修复BeanPath从Map取值为空的问题(issue#790@Github)
|
||||||
* 【poi 】 修复添加图片尺寸的单位问题(issue#I1C2ER@Gitee)
|
* 【poi 】 修复添加图片尺寸的单位问题(issue#I1C2ER@Gitee)
|
||||||
* 【setting】 修复getStr中逻辑问题(pr#113@Gitee)
|
* 【setting】 修复getStr中逻辑问题(pr#113@Gitee)
|
||||||
|
* 【json 】 修复JSONUtil.toXml汉字被编码的问题(pr#795@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
## 5.2.3
|
## 5.2.3
|
||||||
|
@ -444,8 +444,22 @@ public class BeanUtil {
|
|||||||
* @since 4.1.20
|
* @since 4.1.20
|
||||||
*/
|
*/
|
||||||
public static <T> T toBean(Object source, Class<T> clazz) {
|
public static <T> T toBean(Object source, Class<T> clazz) {
|
||||||
|
return toBean(source, clazz, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象或Map转Bean
|
||||||
|
*
|
||||||
|
* @param <T> 转换的Bean类型
|
||||||
|
* @param source Bean对象或Map
|
||||||
|
* @param clazz 目标的Bean类型
|
||||||
|
* @param options 属性拷贝选项
|
||||||
|
* @return Bean对象
|
||||||
|
* @since 5.2.4
|
||||||
|
*/
|
||||||
|
public static <T> T toBean(Object source, Class<T> clazz, CopyOptions options) {
|
||||||
final T target = ReflectUtil.newInstance(clazz);
|
final T target = ReflectUtil.newInstance(clazz);
|
||||||
copyProperties(source, target);
|
copyProperties(source, target, options);
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
package cn.hutool.core.bean.copier.provider;
|
package cn.hutool.core.bean.copier.provider;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanDesc.PropDesc;
|
import cn.hutool.core.bean.BeanDesc.PropDesc;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.bean.copier.ValueProvider;
|
import cn.hutool.core.bean.copier.ValueProvider;
|
||||||
import cn.hutool.core.exceptions.UtilException;
|
import cn.hutool.core.exceptions.UtilException;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bean的值提供者
|
* Bean的值提供者
|
||||||
*
|
*
|
||||||
|
@ -23,7 +23,6 @@ import java.util.UUID;
|
|||||||
* Bean工具单元测试
|
* Bean工具单元测试
|
||||||
*
|
*
|
||||||
* @author Looly
|
* @author Looly
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class BeanUtilTest {
|
public class BeanUtilTest {
|
||||||
|
|
||||||
@ -319,4 +318,24 @@ public class BeanUtilTest {
|
|||||||
public int age;
|
public int age;
|
||||||
public String openid;
|
public String openid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void beanToBeanTest(){
|
||||||
|
// 复现对象无getter方法导致报错的问题
|
||||||
|
Page page1=new Page();
|
||||||
|
BeanUtil.toBean(page1, Page.class, CopyOptions.create().setIgnoreNullValue(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Page {
|
||||||
|
private boolean optimizeCountSql = true;
|
||||||
|
|
||||||
|
public boolean optimizeCountSql() {
|
||||||
|
return optimizeCountSql;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page setOptimizeCountSql(boolean optimizeCountSql) {
|
||||||
|
this.optimizeCountSql = optimizeCountSql;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package cn.hutool.json;
|
package cn.hutool.json;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.CharUtil;
|
import cn.hutool.core.util.CharUtil;
|
||||||
|
import cn.hutool.core.util.EscapeUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.core.util.XmlUtil;
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提供静态方法在XML和JSONObject之间转换
|
* 提供静态方法在XML和JSONObject之间转换
|
||||||
@ -299,11 +299,11 @@ public class XML {
|
|||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
sb.append('\n');
|
sb.append('\n');
|
||||||
}
|
}
|
||||||
sb.append(XmlUtil.escape(val.toString()));
|
sb.append(EscapeUtil.escapeHtml4(val.toString()));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sb.append(XmlUtil.escape(value.toString()));
|
sb.append(EscapeUtil.escapeHtml4(value.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit an array of similar keys
|
// Emit an array of similar keys
|
||||||
@ -345,7 +345,6 @@ public class XML {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object != null) {
|
|
||||||
if (object.getClass().isArray()) {
|
if (object.getClass().isArray()) {
|
||||||
object = new JSONArray(object);
|
object = new JSONArray(object);
|
||||||
}
|
}
|
||||||
@ -360,9 +359,8 @@ public class XML {
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
String string = (object == null) ? StrUtil.NULL : XmlUtil.escape(object.toString());
|
String string = EscapeUtil.escapeHtml4(object.toString());
|
||||||
return (tagName == null) ?
|
return (tagName == null) ?
|
||||||
"\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>"
|
"\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>"
|
||||||
: "<" + tagName + ">" + string + "</" + tagName + ">";
|
: "<" + tagName + ">" + string + "</" + tagName + ">";
|
||||||
|
15
hutool-json/src/test/java/cn/hutool/json/XMLTest.java
Normal file
15
hutool-json/src/test/java/cn/hutool/json/XMLTest.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package cn.hutool.json;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class XMLTest {
|
||||||
|
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
@Test
|
||||||
|
public void toXmlTest(){
|
||||||
|
final JSONObject put = JSONUtil.createObj().put("aaa", "你好").put("键2", "test");
|
||||||
|
final String s = JSONUtil.toXmlStr(put);
|
||||||
|
Assert.assertEquals("<aaa>你好</aaa><键2>test</键2>", s);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user