mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.bean.BeanPath;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.StringWriter;
|
||||
@@ -171,16 +170,4 @@ public interface JSON extends Cloneable, Serializable {
|
||||
default <T> T toBean(final Type type) {
|
||||
return JSONConverter.jsonConvert(type, this, getConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为实体类对象,转换异常将被抛出
|
||||
*
|
||||
* @param <T> Bean类型
|
||||
* @param reference {@link TypeReference}类型参考子类,可以获取其泛型参数中的Type类型
|
||||
* @return 实体类对象
|
||||
* @since 4.2.2
|
||||
*/
|
||||
default <T> T toBean(final TypeReference<T> reference) {
|
||||
return toBean(reference.getType());
|
||||
}
|
||||
}
|
||||
|
@@ -333,6 +333,10 @@ public class JSONUtil {
|
||||
if (obj instanceof CharSequence) {
|
||||
return StrUtil.str((CharSequence) obj);
|
||||
}
|
||||
|
||||
if(obj instanceof Number){
|
||||
return obj.toString();
|
||||
}
|
||||
return toJsonStr(parse(obj, jsonConfig));
|
||||
}
|
||||
|
||||
|
@@ -233,4 +233,18 @@ public class JSONUtilTest {
|
||||
final String xmlStr = JSONUtil.toXmlStr(obj);
|
||||
Assert.assertEquals("<key1>v1</key1><key2>a</key2><key2>b</key2><key2>c</key2>", xmlStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toJsonStrOfStringTest(){
|
||||
String a = "a";
|
||||
final String s = JSONUtil.toJsonStr(a);
|
||||
Assert.assertEquals(a, s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toJsonStrOfNumberTest(){
|
||||
int a = 1;
|
||||
final String s = JSONUtil.toJsonStr(a);
|
||||
Assert.assertEquals("1", s);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user