Java Code Examples for javax.json.JsonObject#isEmpty()
The following examples show how to use
javax.json.JsonObject#isEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlTypeToJsonSchemaConverter.java From iaf with Apache License 2.0 | 7 votes |
public JsonStructure createJsonSchema(String elementName, XSElementDeclaration elementDecl) { JsonObjectBuilder builder = Json.createObjectBuilder(); builder.add("$schema", JSON_SCHEMA); if(elementDecl.getNamespace() != null){ builder.add("$id", elementDecl.getNamespace()); } if(schemaLocation != null){ builder.add("description", "Auto-generated by Frank!Framework based on " + schemaLocation); } if (skipRootElement) { builder.add("$ref", definitionsPath+elementName); } else { builder.add("type", "object").add("additionalProperties", false); builder.add("properties", Json.createObjectBuilder().add(elementName, Json.createObjectBuilder().add("$ref", definitionsPath+elementName).build())); } JsonObject definitionsBuilderResult = getDefinitions(); if(!definitionsBuilderResult.isEmpty()){ builder.add("definitions", definitionsBuilderResult); } return builder.build(); }
Example 2
Source File: StrimziUpgradeST.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
private void changeKafkaAndLogFormatVersion(JsonObject procedures) { if (!procedures.isEmpty()) { String kafkaVersion = procedures.getString("kafkaVersion"); if (!kafkaVersion.isEmpty()) { LOGGER.info("Going to set Kafka version to " + kafkaVersion); KafkaResource.replaceKafkaResource(CLUSTER_NAME, k -> k.getSpec().getKafka().setVersion(kafkaVersion)); LOGGER.info("Wait until kafka rolling update is finished"); if (!kafkaVersion.equals("2.0.0")) { StatefulSetUtils.waitTillSsHasRolled(kafkaStsName, 3, kafkaPods); } makeSnapshots(); } String logMessageVersion = procedures.getString("logMessageVersion"); if (!logMessageVersion.isEmpty()) { LOGGER.info("Going to set log message format version to " + logMessageVersion); KafkaResource.replaceKafkaResource(CLUSTER_NAME, k -> k.getSpec().getKafka().getConfig().put("log.message.format.version", logMessageVersion)); LOGGER.info("Wait until kafka rolling update is finished"); StatefulSetUtils.waitTillSsHasRolled(kafkaStsName, 3, kafkaPods); makeSnapshots(); } } }
Example 3
Source File: JsonpRuntime.java From jmespath-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public List<JsonValue> toList(JsonValue value) { ValueType valueType = value.getValueType(); if (valueType == ARRAY) { return new JsonArrayListWrapper((JsonArray) value); } else if (valueType == OBJECT) { JsonObject obj = (JsonObject) value; if (!obj.isEmpty()) { List<JsonValue> elements = new ArrayList<>(obj.size()); for (JsonValue v : obj.values()) { elements.add(nodeOrNullNode(v)); } return elements; } } return Collections.emptyList(); }
Example 4
Source File: BulkProcessor.java From maximorestclient with Apache License 2.0 | 6 votes |
private void addMeta(JsonObjectBuilder objb, String method, String uri, String... properties){ JsonObjectBuilder objBuilder = Json.createObjectBuilder(); String propStr = this.propertiesBuilder(properties); if(propStr != null){ objBuilder.add("properties", propStr); } if(method != null && !method.isEmpty()){ objBuilder.add("method", method); } if(uri != null && !uri.isEmpty()){ objBuilder.add("uri", uri); } JsonObject objMeta = objBuilder.build(); if(!objMeta.isEmpty()){ objb.add("_meta", objMeta); } this.bulkArray.add(objb.build()); }
Example 5
Source File: GetStatsStep.java From KITE with Apache License 2.0 | 6 votes |
@Override protected void step() throws KiteTestException { try { RTCStatMap statsOverTime = getPCStatOvertime(webDriver, getStatsConfig); statsOverTime.setRegionId(this.runner.getClientRegion()); statsOverTime.setNetworkProfile(this.runner.getNetworkProfile()); RTCStatList localPcStats = statsOverTime.getLocalPcStats(); JsonObject temp = transformToJson(localPcStats); if (!temp.isEmpty()) { for (String pc : statsOverTime.keySet()) { reporter.jsonAttachment(this.report, customName + "Stats(Raw)_" + pc.replaceAll("\"", ""), transformToJson(statsOverTime.get(pc))); reporter.jsonAttachment(this.report, customName + "Stats(Summary)_" + pc.replaceAll("\"", ""), buildStatSummary(statsOverTime.get(pc))); } } } catch (Exception e) { logger.error(getStackTrace(e)); throw new KiteTestException("Failed to getStats", Status.BROKEN, e); } }
Example 6
Source File: AbstractGraphQLTest.java From quarkus with Apache License 2.0 | 5 votes |
protected JsonObject createRequestBody(String graphQL, JsonObject variables) { // Create the request if (variables == null || variables.isEmpty()) { variables = Json.createObjectBuilder().build(); } return Json.createObjectBuilder().add(QUERY, graphQL).add(VARIABLES, variables).build(); }
Example 7
Source File: StrimziUpgradeST.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
private void checkAllImages(JsonObject images) { if (images.isEmpty()) { fail("There are no expected images"); } String zkImage = images.getString("zookeeper"); String kafkaImage = images.getString("kafka"); String tOImage = images.getString("topicOperator"); String uOImage = images.getString("userOperator"); checkContainerImages(kubeClient().getStatefulSet(zkStsName).getSpec().getSelector().getMatchLabels(), zkImage); checkContainerImages(kubeClient().getStatefulSet(kafkaStsName).getSpec().getSelector().getMatchLabels(), kafkaImage); checkContainerImages(kubeClient().getDeployment(eoDepName).getSpec().getSelector().getMatchLabels(), tOImage); checkContainerImages(kubeClient().getDeployment(eoDepName).getSpec().getSelector().getMatchLabels(), 1, uOImage); }
Example 8
Source File: Message.java From sample-room-java with Apache License 2.0 | 5 votes |
/** * Send information about the room to the client. This message is sent after * receiving a `roomHello`. * @param userId * @param roomDescription Room attributes * @return constructed message */ public static Message createLocationMessage(String userId, RoomDescription roomDescription) { // player,<userId>,{ // "type": "location", // "name": "Room name", // "fullName": "Room's descriptive full name", // "description", "Lots of text about what the room looks like", // "exits": { // "shortDirection" : "currentDescription for Player", // "N" : "a dark entranceway" // }, // "commands": { // "/custom" : "Description of what command does" // }, // "roomInventory": ["itemA","itemB"] // } JsonObjectBuilder payload = Json.createObjectBuilder(); payload.add(TYPE, "location"); payload.add("name", roomDescription.getName()); payload.add("fullName", roomDescription.getFullName()); payload.add("description", roomDescription.getDescription()); // convert map of commands into JsonObject JsonObject commands = roomDescription.getCommands(); if ( !commands.isEmpty()) { payload.add("commands", commands); } // Convert list of items into json array JsonArray inventory = roomDescription.getInventory(); if ( !inventory.isEmpty()) { payload.add("roomInventory", inventory); } return new Message(Target.player, userId, payload.build().toString()); }
Example 9
Source File: PayloadMapper.java From component-runtime with Apache License 2.0 | 5 votes |
private void onObject(final Collection<ParameterMeta> definitions, final ParameterMeta meta, final Map<String, String> config, final JsonObjectBuilder json, final String name, final String currentPath) { final JsonObject unflatten = unflatten(currentPath, definitions, config); if (!unflatten.isEmpty()) { json.add(name, unflatten); parameterVisitor.onParameter(meta, unflatten); } else { parameterVisitor.onParameter(meta, JsonValue.NULL); } }
Example 10
Source File: MetricsTest.java From quarkus with Apache License 2.0 | 5 votes |
private JsonObject createRequestBody(String graphQL, JsonObject variables) { // Create the request if (variables == null || variables.isEmpty()) { variables = Json.createObjectBuilder().build(); } return Json.createObjectBuilder().add("query", graphQL).add("variables", variables).build(); }
Example 11
Source File: SystemTestJson.java From tcases with MIT License | 5 votes |
/** * Add any annotatations from the given Annotated object to the given JsonObjectBuilder. */ private static JsonObjectBuilder addAnnotations( JsonObjectBuilder builder, IAnnotated annotated) { JsonObjectBuilder annotations = Json.createObjectBuilder(); toStream( annotated.getAnnotations()).forEach( name -> annotations.add( name, annotated.getAnnotation( name))); JsonObject json = annotations.build(); if( !json.isEmpty()) { builder.add( HAS_KEY, json); } return builder; }
Example 12
Source File: SystemInputJson.java From tcases with MIT License | 5 votes |
/** * Add any annotatations from the given Annotated object to the given JsonObjectBuilder. */ private static JsonObjectBuilder addAnnotations( JsonObjectBuilder builder, IAnnotated annotated) { JsonObjectBuilder annotations = Json.createObjectBuilder(); toStream( annotated.getAnnotations()).forEach( name -> annotations.add( name, annotated.getAnnotation( name))); JsonObject json = annotations.build(); if( !json.isEmpty()) { builder.add( HAS_KEY, json); } return builder; }
Example 13
Source File: RtNetworks.java From docker-java-api with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create network using JsonObjectBuilder. * @param json Json Object Builder object. * @return The created Network. * @throws IOException If something goes wrong. */ private Network createNetwork(final JsonObjectBuilder json) throws IOException { final HttpPost create = new HttpPost( String.format("%s/%s", this.baseUri.toString(), "create") ); try { create.setEntity( new StringEntity( json.build().toString(), ContentType.APPLICATION_JSON ) ); final JsonObject createResult = this.client.execute( create, new ReadJsonObject( new MatchStatus( create.getURI(), HttpStatus.SC_CREATED ) ) ); if (!createResult.isEmpty()) { return new RtNetwork(createResult, this.client, URI.create( String.format("%s/%s", this.baseUri.toString(), createResult.getString("Id")) ), this.docker ); } else { throw new IOException( "Got empty response from Networks.create() method" ); } } finally { create.releaseConnection(); } }
Example 14
Source File: ExecutionDynamicTest.java From microprofile-graphql with Apache License 2.0 | 5 votes |
private JsonObject createRequestBody(String graphQL, JsonObject variables){ JsonObjectBuilder builder = Json.createObjectBuilder(); if(graphQL!=null && !graphQL.isEmpty()) { builder.add(QUERY, graphQL); } if(variables!=null && !variables.isEmpty()) { builder.add(VARIABLES, variables); } return builder.build(); }
Example 15
Source File: Json2Xml.java From iaf with Apache License 2.0 | 5 votes |
@Override public Map<String, String> getAttributes(XSElementDeclaration elementDeclaration, JsonValue node) throws SAXException { if (!readAttributes) { return null; } if (!(node instanceof JsonObject)) { if (log.isTraceEnabled()) log.trace("getAttributes() parent node is not a JsonObject, but a ["+node.getClass().getName()+"] isParentOfSingleMultipleOccurringChildElement ["+isParentOfSingleMultipleOccurringChildElement()+"] value ["+node+"], returning null"); return null; } JsonObject o = (JsonObject)node; if (o.isEmpty()) { if (log.isTraceEnabled()) log.trace("getAttributes() no children"); return null; } try { Map<String, String> result=new HashMap<String,String>(); for (String key:o.keySet()) { if (key.startsWith(attributePrefix)) { String attributeName=key.substring(attributePrefix.length()); String value=getText(elementDeclaration, o.get(key)); if (log.isTraceEnabled()) log.trace("getAttributes() attribute ["+attributeName+"] = ["+value+"]"); result.put(attributeName, value); } } return result; } catch (JsonException e) { throw new SAXException(e); } }
Example 16
Source File: generateFido2PreregisterChallenge.java From fido2 with GNU Lesser General Public License v2.1 | 4 votes |
private JsonObject generateAuthenticatorSelection(RegistrationPolicyOptions regOp, JsonObject options){ JsonObject authselectResponse; AuthenticatorSelection authselect = regOp.getAuthenticatorSelection(); JsonObject rpRequestedAuthSelect = options.getJsonObject(skfsConstants.FIDO2_PREREG_ATTR_AUTHENTICATORSELECT); JsonObjectBuilder authselectBuilder = Json.createObjectBuilder(); // Use RP requested options, assuming the policy allows. if(rpRequestedAuthSelect != null){ String rpRequestedAttachment = rpRequestedAuthSelect.getString(skfsConstants.FIDO2_ATTR_ATTACHMENT, null); Boolean rpRequestedRequireResidentKey = skfsCommon.handleNonExistantJsonBoolean(rpRequestedAuthSelect, skfsConstants.FIDO2_ATTR_RESIDENTKEY); String rpRequestedUserVerification = rpRequestedAuthSelect.getString(skfsConstants.FIDO2_ATTR_USERVERIFICATION, null); if(authselect.getAuthenticatorAttachment().contains(rpRequestedAttachment)){ authselectBuilder.add(skfsConstants.FIDO2_ATTR_ATTACHMENT, rpRequestedAttachment); } else if(rpRequestedAttachment != null){ throw new SKIllegalArgumentException("Policy violation: " + skfsConstants.FIDO2_ATTR_ATTACHMENT); } if(authselect.getRequireResidentKey().contains(rpRequestedRequireResidentKey)){ authselectBuilder.add(skfsConstants.FIDO2_ATTR_RESIDENTKEY, rpRequestedRequireResidentKey); } else if (rpRequestedRequireResidentKey != null) { throw new SKIllegalArgumentException("Policy violation: " + skfsConstants.FIDO2_ATTR_RESIDENTKEY); } if(authselect.getUserVerification().contains(rpRequestedUserVerification)){ authselectBuilder.add(skfsConstants.FIDO2_ATTR_USERVERIFICATION, rpRequestedUserVerification); } else if (rpRequestedUserVerification != null) { throw new SKIllegalArgumentException("Policy violation: " + skfsConstants.FIDO2_ATTR_USERVERIFICATION); } } authselectResponse = authselectBuilder.build(); // If an option is unset, verify the policy allows for the default behavior. if(!authselectResponse.isEmpty()){ if(authselectResponse.getString(skfsConstants.FIDO2_ATTR_RESIDENTKEY, null) == null && !authselect.getRequireResidentKey().contains(false)){ throw new SKIllegalArgumentException("Policy violation: " + skfsConstants.FIDO2_ATTR_RESIDENTKEY + "Missing"); } if(authselectResponse.getString(skfsConstants.FIDO2_ATTR_USERVERIFICATION, null) == null && !authselect.getUserVerification().contains(skfsConstants.POLICY_CONST_PREFERRED)){ throw new SKIllegalArgumentException("Policy violation: " + skfsConstants.FIDO2_ATTR_USERVERIFICATION + "Missing"); } return authselectResponse; } return null; }
Example 17
Source File: FHIRSwaggerGenerator.java From FHIR with Apache License 2.0 | 4 votes |
private static void generatePaths(Class<?> modelClass, JsonObjectBuilder paths, Filter filter) throws Exception { JsonObjectBuilder path = factory.createObjectBuilder(); // FHIR create operation if (filter.acceptOperation(modelClass, "create")) { generateCreatePathItem(modelClass, path); } // FHIR search operation if (filter.acceptOperation(modelClass, "search")) { generateSearchPathItem(modelClass, path); } JsonObject pathObject = path.build(); if (!pathObject.isEmpty()) { paths.add("/" + modelClass.getSimpleName(), pathObject); } path = factory.createObjectBuilder(); // FHIR vread operation if (filter.acceptOperation(modelClass, "vread")) { generateVreadPathItem(modelClass, path); } pathObject = path.build(); if (!pathObject.isEmpty()) { paths.add("/" + modelClass.getSimpleName() + "/{id}/_history/{vid}", pathObject); } path = factory.createObjectBuilder(); // FHIR read operation if (filter.acceptOperation(modelClass, "read")) { generateReadPathItem(modelClass, path); } // FHIR update operation if (filter.acceptOperation(modelClass, "update")) { generateUpdatePathItem(modelClass, path); } // FHIR delete operation if (filter.acceptOperation(modelClass, "delete") && includeDeleteOperation) { generateDeletePathItem(modelClass, path); } pathObject = path.build(); if (!pathObject.isEmpty()) { paths.add("/" + modelClass.getSimpleName() + "/{id}", pathObject); } // FHIR history operation path = factory.createObjectBuilder(); if (filter.acceptOperation(modelClass, "history")) { generateHistoryPathItem(modelClass, path); } pathObject = path.build(); if (!pathObject.isEmpty()) { paths.add("/" + modelClass.getSimpleName() + "/{id}/_history", pathObject); } // TODO: add patch }
Example 18
Source File: FHIROpenApiGenerator.java From FHIR with Apache License 2.0 | 4 votes |
private static void generatePaths(Class<?> modelClass, JsonObjectBuilder paths, Filter filter) throws Exception { JsonObjectBuilder path = factory.createObjectBuilder(); // FHIR create operation if (filter.acceptOperation(modelClass, "create")) { generateCreatePathItem(modelClass, path); } // FHIR search operation if (filter.acceptOperation(modelClass, "search")) { generateSearchPathItem(modelClass, path); } JsonObject pathObject = path.build(); if (!pathObject.isEmpty()) { paths.add("/" + modelClass.getSimpleName(), pathObject); } path = factory.createObjectBuilder(); // FHIR vread operation if (filter.acceptOperation(modelClass, "vread")) { generateVreadPathItem(modelClass, path); } pathObject = path.build(); if (!pathObject.isEmpty()) { paths.add("/" + modelClass.getSimpleName() + "/{id}/_history/{vid}", pathObject); } path = factory.createObjectBuilder(); // FHIR read operation if (filter.acceptOperation(modelClass, "read")) { generateReadPathItem(modelClass, path); } // FHIR update operation if (filter.acceptOperation(modelClass, "update")) { generateUpdatePathItem(modelClass, path); } // FHIR delete operation if (filter.acceptOperation(modelClass, "delete") && includeDeleteOperation) { generateDeletePathItem(modelClass, path); } pathObject = path.build(); if (!pathObject.isEmpty()) { paths.add("/" + modelClass.getSimpleName() + "/{id}", pathObject); } // FHIR history operation path = factory.createObjectBuilder(); if (filter.acceptOperation(modelClass, "history")) { generateHistoryPathItem(modelClass, path); } pathObject = path.build(); if (!pathObject.isEmpty()) { paths.add("/" + modelClass.getSimpleName() + "/{id}/_history", pathObject); } // TODO: add patch }
Example 19
Source File: HFCAClient.java From fabric-sdk-java with Apache License 2.0 | 4 votes |
private String revokeInternal(User revoker, String revokee, String reason, boolean genCRL) throws RevocationException, InvalidArgumentException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } logger.debug(format("revoke revoker: %s, revokee: %s, reason: %s", revoker, revokee, reason)); if (Utils.isNullOrEmpty(revokee)) { throw new InvalidArgumentException("revokee user is not set"); } if (revoker == null) { throw new InvalidArgumentException("revoker is not set"); } try { setUpSSL(); // build request body RevocationRequest req = new RevocationRequest(caName, revokee, null, null, reason, genCRL); String body = req.toJson(); // send revoke request JsonObject resp = httpPost(url + HFCA_REVOKE, body, revoker); logger.debug(format("revoke revokee: %s done.", revokee)); if (genCRL) { if (resp.isEmpty()) { throw new RevocationException("Failed to return CRL, revoke response is empty"); } if (resp.isNull("CRL")) { throw new RevocationException("Failed to return CRL"); } return resp.getString("CRL"); } return null; } catch (Exception e) { logger.error(e.getMessage(), e); throw new RevocationException("Error while revoking the user. " + e.getMessage(), e); } }
Example 20
Source File: generateFido2PreregisterChallenge_v1.java From fido2 with GNU Lesser General Public License v2.1 | 4 votes |
private JsonObject generateAuthenticatorSelection(RegistrationPolicyOptions regOp, JsonObject options){ JsonObject authselectResponse; AuthenticatorSelection authselect = regOp.getAuthenticatorSelection(); JsonObject rpRequestedAuthSelect = options.getJsonObject(skfsConstants.FIDO2_PREREG_ATTR_AUTHENTICATORSELECT); JsonObjectBuilder authselectBuilder = Json.createObjectBuilder(); // Use RP requested options, assuming the policy allows. if(rpRequestedAuthSelect != null){ String rpRequestedAttachment = rpRequestedAuthSelect.getString(skfsConstants.FIDO2_ATTR_ATTACHMENT, null); Boolean rpRequestedRequireResidentKey = skfsCommon.handleNonExistantJsonBoolean(rpRequestedAuthSelect, skfsConstants.FIDO2_ATTR_RESIDENTKEY); String rpRequestedUserVerification = rpRequestedAuthSelect.getString(skfsConstants.FIDO2_ATTR_USERVERIFICATION, null); if(authselect.getAuthenticatorAttachment().contains(rpRequestedAttachment)){ authselectBuilder.add(skfsConstants.FIDO2_ATTR_ATTACHMENT, rpRequestedAttachment); } else if(rpRequestedAttachment != null){ throw new SKIllegalArgumentException("Policy violation: " + skfsConstants.FIDO2_ATTR_ATTACHMENT); } if(authselect.getRequireResidentKey().contains(rpRequestedRequireResidentKey)){ authselectBuilder.add(skfsConstants.FIDO2_ATTR_RESIDENTKEY, rpRequestedRequireResidentKey); } else if (rpRequestedRequireResidentKey != null) { throw new SKIllegalArgumentException("Policy violation: " + skfsConstants.FIDO2_ATTR_RESIDENTKEY); } if(authselect.getUserVerification().contains(rpRequestedUserVerification)){ authselectBuilder.add(skfsConstants.FIDO2_ATTR_USERVERIFICATION, rpRequestedUserVerification); } else if (rpRequestedUserVerification != null) { throw new SKIllegalArgumentException("Policy violation: " + skfsConstants.FIDO2_ATTR_USERVERIFICATION); } } authselectResponse = authselectBuilder.build(); // If an option is unset, verify the policy allows for the default behavior. if(!authselectResponse.isEmpty()){ if(authselectResponse.getString(skfsConstants.FIDO2_ATTR_RESIDENTKEY, null) == null && !authselect.getRequireResidentKey().contains(false)){ throw new SKIllegalArgumentException("Policy violation: " + skfsConstants.FIDO2_ATTR_RESIDENTKEY + "Missing"); } if(authselectResponse.getString(skfsConstants.FIDO2_ATTR_USERVERIFICATION, null) == null && !authselect.getUserVerification().contains(skfsConstants.POLICY_CONST_PREFERRED)){ throw new SKIllegalArgumentException("Policy violation: " + skfsConstants.FIDO2_ATTR_USERVERIFICATION + "Missing"); } return authselectResponse; } return null; }