本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.asBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.asBoolean方法的具体用法?Java JsonNode.asBoolean怎么用?Java JsonNode.asBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.asBoolean方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Applies this schema rule to take the required code generation steps.
* <p>
* The required rule simply adds a note to the JavaDoc comment to mark a
* property as required.
*
* @param nodeName
* the name of the schema node for which this "required" rule has
* been added
* @param node
* the "required" node, having a value <code>true</code> or
* <code>false</code>
* @param generatableType
* the class or method which may be marked as "required"
* @return the JavaDoc comment attached to the generatableType, which
* <em>may</em> have an added not to mark this construct as
* required.
*/
@Override
public JDocCommentable apply(String nodeName, JsonNode node, JDocCommentable generatableType, Schema schema) {
if (node.asBoolean()) {
generatableType.javadoc().append("\n(Required)");
if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()
&& generatableType instanceof JFieldVar) {
((JFieldVar) generatableType).annotate(NotNull.class);
}
if (ruleFactory.getGenerationConfig().isIncludeJsr305Annotations()
&& generatableType instanceof JFieldVar) {
((JFieldVar) generatableType).annotate(Nonnull.class);
}
} else {
if (ruleFactory.getGenerationConfig().isIncludeJsr305Annotations()
&& generatableType instanceof JFieldVar) {
((JFieldVar) generatableType).annotate(Nullable.class);
}
}
return generatableType;
}
示例2: transToValue
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* convert into value.
* @param valueNode the BaseType JsonNode
* @param baseType BooleanBaseType or IntegerBaseType or RealBaseType or
* StringBaseType or UuidBaseType
* @return Object the value of JsonNode
*/
public static Object transToValue(JsonNode valueNode, BaseType baseType) {
if (baseType instanceof BooleanBaseType) {
return valueNode.asBoolean();
} else if (baseType instanceof IntegerBaseType) {
return valueNode.asInt();
} else if (baseType instanceof RealBaseType) {
return valueNode.asDouble();
} else if (baseType instanceof StringBaseType) {
return valueNode.asText();
} else if (baseType instanceof UuidBaseType) {
if (valueNode.isArray()) {
if (valueNode.size() == 2) {
if (valueNode.get(0).isTextual()
&& ("uuid".equals(valueNode.get(0).asText()) || "named-uuid"
.equals(valueNode.get(0).asText()))) {
return Uuid.uuid(valueNode.get(1).asText());
}
}
} else {
return new RefTableRow(((UuidBaseType) baseType).getRefTable(), valueNode);
}
}
return null;
}
示例3: matchLinkTypeConstraint
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Matches a link type constraint against a JSON representation of the
* constraint.
*
* @param linkTypeConstraint constraint object to match
* @param constraintJson JSON representation of the constraint
* @return true if the constraint and JSON match, false otherwise.
*/
private boolean matchLinkTypeConstraint(LinkTypeConstraint linkTypeConstraint,
JsonNode constraintJson) {
final JsonNode inclusiveJson = constraintJson.get("inclusive");
final JsonNode typesJson = constraintJson.get("types");
if (typesJson.size() != linkTypeConstraint.types().size()) {
return false;
}
int foundType = 0;
for (Link.Type type : linkTypeConstraint.types()) {
for (int jsonIndex = 0; jsonIndex < typesJson.size(); jsonIndex++) {
if (type.name().equals(typesJson.get(jsonIndex).asText())) {
foundType++;
break;
}
}
}
return (inclusiveJson != null &&
inclusiveJson.asBoolean() == linkTypeConstraint.isInclusive()) &&
foundType == typesJson.size();
}
示例4: getJsonValue
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static Object getJsonValue(JsonNode input, String name, Class type, boolean isRequired, Object defaultValue) throws IllegalArgumentException {
JsonNode node = input.findPath(name);
if (node.isMissingNode() || node.isNull()) {
if (isRequired) {
throw new IllegalArgumentException(name + " is required!");
} else {
return defaultValue;
}
}
if (type.equals(String.class)) {
return node.textValue();
}
if (type.equals(Integer.class)) {
return node.asInt();
}
if (type.equals(Long.class)) {
return node.asLong();
}
if (type.equals(Boolean.class)) {
return node.asBoolean();
}
if (type.equals(Double.class)) {
return node.asDouble();
}
return node.asText();
}
示例5: checkGatewaySession
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void checkGatewaySession() {
Device device = deviceSessionCtx.getDevice();
if (device != null) {
JsonNode infoNode = device.getAdditionalInfo();
if (infoNode != null) {
JsonNode gatewayNode = infoNode.get("gateway");
if (gatewayNode != null && gatewayNode.asBoolean()) {
// gatewaySessionCtx = new GatewaySessionCtx(processor, deviceService,
// authService, relationService,
// deviceSessionCtx);
}
}
}
}
示例6: nodeValue
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private boolean nodeValue(ObjectNode obj, String fieldName, boolean defaultValue)
{
final JsonNode node = obj.get(fieldName);
if( node == null )
{
return defaultValue;
}
return node.asBoolean(defaultValue);
}
示例7: getJsUrl
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public String getJsUrl()
{
final JsonNode minified = extra.get("minified");
if( minified != null && minified.asBoolean() )
{
return PathUtils.urlPath(baseUrl, "editor_plugin.js");
}
return PathUtils.urlPath(baseUrl, "editor_plugin_src.js");
}
示例8: getSimpleMemberValue
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private Object getSimpleMemberValue(JsonNode currentNode, MemberModel memberModel) {
if (memberModel.getHttp().getIsStreaming()) {
return null;
}
switch (memberModel.getVariable().getSimpleType()) {
case "Long":
return currentNode.asLong();
case "Integer":
return currentNode.asInt();
case "String":
return currentNode.asText();
case "Boolean":
return currentNode.asBoolean();
case "Double":
return currentNode.asDouble();
case "Instant":
return Instant.ofEpochMilli(currentNode.asLong());
case "ByteBuffer":
return ByteBuffer.wrap(currentNode.asText().getBytes(StandardCharsets.UTF_8));
case "Float":
return (float) currentNode.asDouble();
case "Character":
return asCharacter(currentNode);
default:
throw new IllegalArgumentException(
"Unsupported fieldType " + memberModel.getVariable().getSimpleType());
}
}
示例9: isDurable
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Returns if link is durable in the network model or not.
*
* @return true for durable, false otherwise
*/
public Boolean isDurable() {
JsonNode res = object.path(IS_DURABLE);
if (res.isMissingNode()) {
return null;
}
return res.asBoolean();
}
示例10: apply
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Applies this schema rule to take the required code generation steps.
* <p>
* If additionalProperties is specified and set to the boolean value
* <code>false</code>, this rule does not make any change to the generated
* Java type (the type does not allow additional properties).
* <p>
* If the additionalProperties node is <code>null</code> (not specified in
* the schema) or empty, then a new bean property named
* "additionalProperties", of type {@link Map}{@literal <String,Object>} is
* added to the generated type (with appropriate accessors). The accessors
* are annotated to allow unrecognised (additional) properties found in JSON
* data to be marshalled/unmarshalled from/to this map.
* <p>
* If the additionalProperties node is present and specifies a schema, then
* an "additionalProperties" map is added to the generated type. This time
* the map values will be restricted and must be instances of a newly
* generated Java type that will be created based on the
* additionalProperties schema provided. If the schema does not specify the
* javaType property, the name of the newly generated type will be derived
* from the nodeName and the suffix 'Property'.
*
* @param nodeName
* the name of the schema node for which the additionalProperties
* node applies
* @param node
* the additionalProperties node itself, found in the schema (may
* be null if not specified in the schema)
* @param jclass
* the Java type that is being generated to represent this schema
* @return the given Java type jclass
*/
@Override
public JDefinedClass apply(String nodeName, JsonNode node, JDefinedClass jclass, Schema schema) {
if (node != null && node.isBoolean() && node.asBoolean() == false) {
// no additional properties allowed
return jclass;
}
if (!this.ruleFactory.getGenerationConfig().isIncludeAdditionalProperties()) {
// no additional properties allowed
return jclass;
}
if (!ruleFactory.getAnnotator().isAdditionalPropertiesSupported()) {
// schema allows additional properties, but serializer library can't support them
return jclass;
}
JType propertyType;
if (node != null && node.size() != 0) {
propertyType = ruleFactory.getSchemaRule().apply(nodeName + "Property", node, jclass, schema);
} else {
propertyType = jclass.owner().ref(Object.class);
}
JFieldVar field = addAdditionalPropertiesField(jclass, propertyType);
addGetter(jclass, field);
addSetter(jclass, propertyType, field);
if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()) {
ruleFactory.getValidRule().apply(nodeName, node, field, schema);
}
if (ruleFactory.getGenerationConfig().isGenerateBuilders()) {
addBuilder(jclass, propertyType, field);
}
return jclass;
}
示例11: getNodeData
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public Object getNodeData(Schema schema, JsonNode node) {
if (node == null || node.isNull()) {
return null;
}
switch (schema.getType()) {
case INT:
Preconditions.checkArgument(node.isNumber());
return node.asInt();
case LONG:
Preconditions.checkArgument(node.isNumber());
return node.asLong();
case BOOLEAN:
Preconditions.checkArgument(node.isBoolean());
return node.asBoolean();
case DOUBLE:
Preconditions.checkArgument(node.isNumber());
return node.asDouble();
case FLOAT:
Preconditions.checkArgument(node.isNumber());
return Double.valueOf(node.asDouble()).floatValue();
case BYTES:
Preconditions.checkArgument(node.isTextual());
String base64 = node.asText();
return ByteArray.fromBase64(base64);
case ENUM:
Preconditions.checkArgument(node.isTextual());
String enumConst = node.asText();
EnumSchema es = (EnumSchema) schema;
return es.getConstant(enumConst);
case STRING:
Preconditions.checkArgument(node.isTextual());
return node.asText();
case MAP:
return readMap((MapSchema) schema, node);
case LIST:
Preconditions.checkArgument(node.isArray());
return readList((ListSchema) schema, node);
case RECORD:
Preconditions.checkArgument(node.isObject());
return readRecord((RecordSchema) schema, node);
case ANY:
Preconditions.checkArgument(node.isObject());
return readAny(node);
default:
throw new IllegalArgumentException("Unknown schema type " + schema.getType());
}
}
示例12: fromJsonNode
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void fromJsonNode(JsonNode node) {
JsonNodeType nodeType = node.getNodeType();
switch (nodeType) {
case STRING:
type = Schema.Type.STRING;
value = node.asText();
break;
case NUMBER:
double number = node.asDouble();
if (number == Math.floor(number)) {
type = Schema.Type.INTEGER;
value = (int) number;
} else {
type = Schema.Type.FLOAT;
value = number;
}
break;
case BOOLEAN:
type = Schema.Type.BOOLEAN;
value = node.asBoolean();
break;
case ARRAY:
List<Node> list = new LinkedList<>();
type = Schema.Type.LIST;
for (int i = 0; i < node.size(); i++) {
list.add(new Node(node.get(i)));
}
value = list;
break;
case OBJECT:
Map<String, Node> struct = new HashMap<>();
type = Schema.Type.STRUCT;
for (Iterator<String> properties = node.fieldNames(); properties.hasNext(); ) {
String property = properties.next();
struct.put(property, new Node(node.get(property)));
}
value = struct;
break;
default:
throw new RuntimeException("Unsupported JSON type");
}
}
示例13: decode
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public MeterRequest decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
final JsonCodec<Band> meterBandCodec = context.codec(Band.class);
CoreService coreService = context.getService(CoreService.class);
// parse device id
DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID),
DEVICE_ID + MISSING_MEMBER_MESSAGE).asText());
// application id
ApplicationId appId = coreService.registerApplication(REST_APP_ID);
// parse burst
boolean burst = false;
JsonNode burstJson = json.get("burst");
if (burstJson != null) {
burst = burstJson.asBoolean();
}
// parse unit type
String unit = nullIsIllegal(json.get(UNIT), UNIT + MISSING_MEMBER_MESSAGE).asText();
Meter.Unit meterUnit;
switch (unit) {
case "KB_PER_SEC":
meterUnit = Meter.Unit.KB_PER_SEC;
break;
case "PKTS_PER_SEC":
meterUnit = Meter.Unit.PKTS_PER_SEC;
break;
default:
log.warn("The requested unit {} is not defined for meter.", unit);
return null;
}
// parse meter bands
List<Band> bandList = new ArrayList<>();
JsonNode bandsJson = json.get(BANDS);
checkNotNull(bandsJson);
if (bandsJson != null) {
IntStream.range(0, bandsJson.size()).forEach(i -> {
ObjectNode bandJson = get(bandsJson, i);
bandList.add(meterBandCodec.decode(bandJson, context));
});
}
MeterRequest meterRequest;
if (burst) {
meterRequest = DefaultMeterRequest.builder()
.fromApp(appId)
.forDevice(deviceId)
.withUnit(meterUnit)
.withBands(bandList)
.burst().add();
} else {
meterRequest = DefaultMeterRequest.builder()
.fromApp(appId)
.forDevice(deviceId)
.withUnit(meterUnit)
.withBands(bandList).add();
}
return meterRequest;
}
示例14: getJsonAsBool
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
*
* 从json串中获取某key对应的值<br>
*
* @param jsonSrc
* @param jsonKey
* @return
* String
* @Author fanyaowu
* @data 2014年7月16日
* @exception
* @version
*
*/
public static boolean getJsonAsBool(String jsonSrc, String jsonKey)
{
JsonNode node = JsonUtils.json2obj(jsonSrc, JsonNode.class);
// 获取jsonKey数据
JsonNode dataNode = node.get(jsonKey);
return dataNode.asBoolean();
}