当前位置: 首页>>代码示例>>Java>>正文


Java JsonPrimitive.getAsBoolean方法代码示例

本文整理汇总了Java中com.google.gson.JsonPrimitive.getAsBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java JsonPrimitive.getAsBoolean方法的具体用法?Java JsonPrimitive.getAsBoolean怎么用?Java JsonPrimitive.getAsBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.JsonPrimitive的用法示例。


在下文中一共展示了JsonPrimitive.getAsBoolean方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: primitive

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
/**
 * Converts a JsonPrimitive into a primitive Boolean, Double, or String.
 * 
 * @param p
 *          : JsonPrimitive
 * @return Boolean, Double, or String
 */
public static Object primitive(JsonPrimitive p) {
  Object retVal = null;
  if (p.isBoolean()) {
    retVal = p.getAsBoolean();
  } else if (p.isNumber()) {
    double doubleVal = p.getAsDouble();

    if (doubleVal == Math.rint(doubleVal)) {
      retVal = (int) doubleVal;
    } else {
      retVal = doubleVal;
    }
  } else if (p.isString()) {
    retVal = p.getAsString();
  }
  return retVal;
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:25,代码来源:Utilities.java

示例2: deserializeValue

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private Object deserializeValue(JsonPrimitive val, org.eclipse.leshan.core.model.ResourceModel.Type expectedType) {
    switch (expectedType) {
    case BOOLEAN:
        return val.getAsBoolean();
    case STRING:
        return val.getAsString();
    case INTEGER:
        return val.getAsLong();
    case FLOAT:
        return val.getAsDouble();
    case TIME:
    case OPAQUE:
    default:
        // TODO we need to better handle this.
        return val.getAsString();
    }
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:18,代码来源:LwM2mNodeDeserializer.java

示例3: unwarpPrimitive

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public Object unwarpPrimitive(JsonPrimitive primitive) {
    if (primitive.isBoolean()) {
        return primitive.getAsBoolean();
    } else if (primitive.isNumber()) {
        return primitive.getAsNumber();
    } else if (primitive.isString()) {
        return primitive.getAsString();
    } else {
        throw new IllegalArgumentException("Unknown primitive type: " + primitive);
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:13,代码来源:AbstractGsonConverter.java

示例4: read

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
public Object read(JsonElement in) {
  
  if (in.isJsonArray()) {
    List<Object> list = new ArrayList<Object>();
    JsonArray arr = in.getAsJsonArray();
    for (JsonElement anArr : arr) {
      list.add(read(anArr));
    }
    return list;
  } else if (in.isJsonObject()) {
    Map<String, Object> map = new LinkedTreeMap<String, Object>();
    JsonObject obj = in.getAsJsonObject();
    Set<Map.Entry<String, JsonElement>> entitySet = obj.entrySet();
    for (Map.Entry<String, JsonElement> entry: entitySet) {
      map.put(entry.getKey(), read(entry.getValue()));
    }
    return map;
  } else if (in.isJsonPrimitive()) {
    JsonPrimitive prim = in.getAsJsonPrimitive();
    if (prim.isBoolean()) {
      return prim.getAsBoolean();
    } else if (prim.isString()) {
      return prim.getAsString();
    } else if (prim.isNumber()) {
      Number num = prim.getAsNumber();
      // here you can handle double int/long values
      // and return any type you want
      // this solution will transform 3.0 float to long values
      if (Math.abs(Math.ceil(num.doubleValue())-num.longValue()) < .0000001) {
        return num.intValue();
      } else {
        return num.doubleValue();
      }
    }
  }
  return null;
}
 
开发者ID:Huawei,项目名称:Server_Management_Common_eSightApi,代码行数:38,代码来源:JsonUtil.java

示例5: isHiddenSession

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private boolean isHiddenSession(JsonObject sessionObj) {
  JsonPrimitive hide = getMapValue(
          get(sessionObj, InputJsonKeys.VendorAPISource.Topics.info),
          InputJsonKeys.VendorAPISource.Topics.INFO_HIDDEN_SESSION,
          Converters.BOOLEAN, null);
  if (hide != null && hide.isBoolean() && hide.getAsBoolean()) {
    return true;
  }
  return false;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:11,代码来源:DataExtractor.java

示例6: isFeatured

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
/** Check whether a session is featured or not.
 *
 * @param sessionObj Session to check
 * @return True if featured, false otherwise.
 */
private boolean isFeatured(JsonObject sessionObj) {
  // Extract "Featured Session" flag from EventPoint "info" block.
  JsonPrimitive featured = getMapValue(
          get(sessionObj, InputJsonKeys.VendorAPISource.Topics.info),
          InputJsonKeys.VendorAPISource.Topics.INFO_FEATURED_SESSION,
          Converters.BOOLEAN, null);
  if (featured != null && featured.isBoolean() && featured.getAsBoolean()) {
    return true;
  }
  return false;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:17,代码来源:DataExtractor.java

示例7: replaceWithTestData

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private static String replaceWithTestData(final JsonElement sourceTestData, String inputString) {
if(sourceTestData != null) {
        if(inputString != null) {
            if(inputString.startsWith("$(") && inputString.endsWith(")")) {
                inputString = inputString.substring("$(".length(), inputString.length() - ")".length());

                String[] pathElements = inputString.split("\\.");
                if(pathElements != null && pathElements.length > 0) {
                    JsonElement elemPointer = sourceTestData;
                    for(String element : pathElements) {
                        if(elemPointer.isJsonObject() && elemPointer.getAsJsonObject().has(element)) {
                            elemPointer = elemPointer.getAsJsonObject().get(element);
                            continue;
                        }
                        else {
                            elemPointer = null;
                            break;
                        }
                    }
                    if(elemPointer != null && elemPointer.isJsonPrimitive()) {
                        JsonPrimitive primitive = elemPointer.getAsJsonPrimitive();
                        if(primitive.isString() || primitive.isNumber())
                            return primitive.getAsString();
                        else if(primitive.isBoolean())
                            return primitive.getAsBoolean()?"true":"false";
                    }
                }
            }
        }
    }
    return inputString;
}
 
开发者ID:andrewjc,项目名称:kheera-testrunner-android,代码行数:33,代码来源:TableConverter.java

示例8: execute

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
public void execute() throws IOException, URISyntaxException, AuthenticationException {
      JsonObject responseJson = new JsonObject();
      WorkItemMover mover = new WorkItemMover(parentService);
      boolean isMoved = false;
      boolean previewOnly = false;
      Collection<AttributeDefinition> moveResults = null;

      // read request data
      JsonObject workItemData = RequestReader.readAsJson(request);
      JsonPrimitive previewPrimitive = workItemData.getAsJsonPrimitive("previewOnly");
      JsonPrimitive targetPA = workItemData.getAsJsonPrimitive("targetProjectArea");
      JsonArray workItemJson = workItemData.getAsJsonArray("workItems");
      JsonArray typeMappingJson = workItemData.getAsJsonArray("typeMapping");
      JsonArray attributesJson = workItemData.getAsJsonArray("mapping");

      if(previewPrimitive != null) {
          previewOnly = previewPrimitive.getAsBoolean();
      }
      // map cient data to model
      Collection<Integer> clientWorkItemList = gson.fromJson(workItemJson, workItemIdCollectionType);
      Collection<AttributeDefinition> clientMappingDefinitions = gson.fromJson(attributesJson, attributesCollectionType);
      Collection<TypeMappingEntry> typeMappingDefinitions = gson.fromJson(typeMappingJson, typeMappingCollectionType);
      Map<String, String> typeMap = new HashMap<String, String>();
      for (TypeMappingEntry def : typeMappingDefinitions) {
          typeMap.put(def.getSource(), def.getTarget());
      }

      try {
          // fetch full work item information
	List<IWorkItem> items = WorkItemHelpers.fetchWorkItems(clientWorkItemList, workItemServer, monitor);

          // resolve project area
          IProjectAreaHandle targetArea = ProjectAreaHelpers.getProjectArea(targetPA.getAsString(), parentService);

          // prepare movement and track fields to be changed
	MovePreparationResult preparationResult = mover.PrepareMove(items, targetArea, clientMappingDefinitions, typeMap);

	// store attribute based ovservations to be able to return this information to the end user
	moveResults = preparationResult.getAttributeDefinitions().getAttributeDefinitionCollection();

	if(!previewOnly) {
              // try to move the work items...
              IStatus status = mover.MoveAll(preparationResult.getWorkItems());
              isMoved = status.isOK();
          }
} catch (Exception e) {
          // Inform the user the the items could not be moved
          responseJson.addProperty("error", e.getMessage());
}

      // prepare data to be returend
      responseJson.addProperty("successful", isMoved);
      responseJson.add("mapping", gson.toJsonTree(moveResults, resultsType));
      response.getWriter().write(gson.toJson(responseJson));
  }
 
开发者ID:jazz-community,项目名称:rtc-workitem-bulk-mover-service,代码行数:56,代码来源:MoveService.java


注:本文中的com.google.gson.JsonPrimitive.getAsBoolean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。