Decodes a String into an object of the specified type
2016-03-16 08:59
627 查看
/**
* Decodes a String into an object of the specified type. If the object
* type is not supported, null will be returned.
*
* @param type the type of the property.
* @param value the encode String value to decode.
* @return the String value decoded into the specified type.
* @throws Exception If decoding failed due to an error.
*/
private static Object decode(Class<?> type, String value) throws Exception {
if (type.getName().equals("java.lang.String")) {
return value;
}
if (type.getName().equals("boolean")) {
return Boolean.valueOf(value);
}
if (type.getName().equals("int")) {
return Integer.valueOf(value);
}
if (type.getName().equals("long")) {
return Long.valueOf(value);
}
if (type.getName().equals("float")) {
return Float.valueOf(value);
}
if (type.getName().equals("double")) {
return Double.valueOf(value);
}
if (type.getName().equals("java.lang.Class")) {
return Class.forName(value);
}
return null;
}
* Decodes a String into an object of the specified type. If the object
* type is not supported, null will be returned.
*
* @param type the type of the property.
* @param value the encode String value to decode.
* @return the String value decoded into the specified type.
* @throws Exception If decoding failed due to an error.
*/
private static Object decode(Class<?> type, String value) throws Exception {
if (type.getName().equals("java.lang.String")) {
return value;
}
if (type.getName().equals("boolean")) {
return Boolean.valueOf(value);
}
if (type.getName().equals("int")) {
return Integer.valueOf(value);
}
if (type.getName().equals("long")) {
return Long.valueOf(value);
}
if (type.getName().equals("float")) {
return Float.valueOf(value);
}
if (type.getName().equals("double")) {
return Double.valueOf(value);
}
if (type.getName().equals("java.lang.Class")) {
return Class.forName(value);
}
return null;
}
相关文章推荐
- ES5 对象的扩展(Object.preventExtensions)、密封(Object.seal)和冻结(Object.freeze)
- object-c内存布局
- Objective—C语言的新魅力
- Object-C基础-01-概述
- Objective-C中,ARC下的 strong和weak指针原理解释
- Object-C非正式协议与正式协议的区别
- 面向对象编程(四)继承,概念及super关键字,final关键字,Object类常见方法
- 2016-02-01_2&nbsp;&nbsp;Object类
- 论a different object with the same identifier value
- UML 对象图 object diagram
- PostgreSQL中 drop table指令出现ERROR: cannot drop table userinfo because other objects depend on it
- android json解析java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1报错
- Java中Object类的公有方法
- JavaScript prototype of object
- Object调用控件的办法
- Object详解
- 看啦这么就别人的博客 我也来写一篇! Object转换其他类型
- objective-c感悟(三)属性之谜
- Objective-C中的KVC和KVO
- Objective-C Runtime