本文整理汇总了Java中com.alibaba.fastjson.util.TypeUtils.castToBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java TypeUtils.castToBoolean方法的具体用法?Java TypeUtils.castToBoolean怎么用?Java TypeUtils.castToBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.util.TypeUtils
的用法示例。
在下文中一共展示了TypeUtils.castToBoolean方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBoolean
import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public Boolean getBoolean(String key) {
Object value = get(key);
if (value == null) {
return null;
}
return TypeUtils.castToBoolean(value);
}
示例2: deserialze
import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
Boolean boolObj;
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 6) {
lexer.nextToken(16);
boolObj = Boolean.TRUE;
} else if (lexer.token() == 7) {
lexer.nextToken(16);
boolObj = Boolean.FALSE;
} else if (lexer.token() == 2) {
int intValue = lexer.intValue();
lexer.nextToken(16);
if (intValue == 1) {
boolObj = Boolean.TRUE;
} else {
boolObj = Boolean.FALSE;
}
} else {
Object value = parser.parse();
if (value == null) {
return null;
}
boolObj = TypeUtils.castToBoolean(value);
}
if (clazz == AtomicBoolean.class) {
return new AtomicBoolean(boolObj.booleanValue());
}
return boolObj;
}
示例3: getBoolean
import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public Boolean getBoolean(int index) {
Object value = get(index);
if (value == null) {
return null;
}
return TypeUtils.castToBoolean(value);
}
示例4: deserialze
import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
final JSONLexer lexer = parser.getLexer();
Boolean boolObj;
if (lexer.token() == JSONToken.TRUE) {
lexer.nextToken(JSONToken.COMMA);
boolObj = Boolean.TRUE;
} else if (lexer.token() == JSONToken.FALSE) {
lexer.nextToken(JSONToken.COMMA);
boolObj = Boolean.FALSE;
} else if (lexer.token() == JSONToken.LITERAL_INT) {
int intValue = lexer.intValue();
lexer.nextToken(JSONToken.COMMA);
if (intValue == 1) {
boolObj = Boolean.TRUE;
} else {
boolObj = Boolean.FALSE;
}
} else {
Object value = parser.parse();
if (value == null) {
return null;
}
boolObj = TypeUtils.castToBoolean(value);
}
if (clazz == AtomicBoolean.class) {
return (T) new AtomicBoolean(boolObj.booleanValue());
}
return (T) boolObj;
}
示例5: deserialze
import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
final JSONLexer lexer = parser.lexer;
Boolean boolObj;
try {
if (lexer.token() == JSONToken.TRUE) {
lexer.nextToken(JSONToken.COMMA);
boolObj = Boolean.TRUE;
} else if (lexer.token() == JSONToken.FALSE) {
lexer.nextToken(JSONToken.COMMA);
boolObj = Boolean.FALSE;
} else if (lexer.token() == JSONToken.LITERAL_INT) {
int intValue = lexer.intValue();
lexer.nextToken(JSONToken.COMMA);
if (intValue == 1) {
boolObj = Boolean.TRUE;
} else {
boolObj = Boolean.FALSE;
}
} else {
Object value = parser.parse();
if (value == null) {
return null;
}
boolObj = TypeUtils.castToBoolean(value);
}
} catch (Exception ex) {
throw new JSONException("parseBoolean error, field : " + fieldName, ex);
}
if (clazz == AtomicBoolean.class) {
return (T) new AtomicBoolean(boolObj.booleanValue());
}
return (T) boolObj;
}
示例6: parseField
import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
boolean booleanValue = true;
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 6) {
lexer.nextToken(16);
if (object == null) {
fieldValues.put(this.fieldInfo.getName(), Boolean.TRUE);
} else {
setValue(object, true);
}
} else if (lexer.token() == 2) {
int val = lexer.intValue();
lexer.nextToken(16);
if (val != 1) {
booleanValue = false;
}
if (object == null) {
fieldValues.put(this.fieldInfo.getName(), Boolean.valueOf(booleanValue));
} else {
setValue(object, booleanValue);
}
} else if (lexer.token() == 8) {
lexer.nextToken(16);
if (getFieldClass() != Boolean.TYPE && object != null) {
setValue(object, null);
}
} else if (lexer.token() == 7) {
lexer.nextToken(16);
if (object == null) {
fieldValues.put(this.fieldInfo.getName(), Boolean.FALSE);
} else {
setValue(object, false);
}
} else {
Boolean value = TypeUtils.castToBoolean(parser.parse());
if (value != null || getFieldClass() != Boolean.TYPE) {
if (object == null) {
fieldValues.put(this.fieldInfo.getName(), value);
} else {
setValue(object, (Object) value);
}
}
}
}
示例7: parseField
import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
Boolean value;
final JSONLexer lexer = parser.getLexer();
if (lexer.token() == JSONToken.TRUE) {
lexer.nextToken(JSONToken.COMMA);
if (object == null) {
fieldValues.put(fieldInfo.getName(), Boolean.TRUE);
} else {
setValue(object, true);
}
return;
}
if (lexer.token() == JSONToken.LITERAL_INT) {
int val = lexer.intValue();
lexer.nextToken(JSONToken.COMMA);
boolean booleanValue = val == 1;
if (object == null) {
fieldValues.put(fieldInfo.getName(), booleanValue);
} else {
setValue(object, booleanValue);
}
return;
}
if (lexer.token() == JSONToken.NULL) {
value = null;
lexer.nextToken(JSONToken.COMMA);
if (getFieldClass() == boolean.class) {
// skip
return;
}
if (object != null) {
setValue(object, null);
}
return;
}
if (lexer.token() == JSONToken.FALSE) {
lexer.nextToken(JSONToken.COMMA);
if (object == null) {
fieldValues.put(fieldInfo.getName(), Boolean.FALSE);
} else {
setValue(object, false);
}
return;
}
Object obj = parser.parse();
value = TypeUtils.castToBoolean(obj);
if (value == null && getFieldClass() == boolean.class) {
// skip
return;
}
if (object == null) {
fieldValues.put(fieldInfo.getName(), value);
} else {
setValue(object, value);
}
}