本文整理汇总了Java中javax.json.Json类的典型用法代码示例。如果您正苦于以下问题:Java Json类的具体用法?Java Json怎么用?Java Json使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Json类属于javax.json包,在下文中一共展示了Json类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseJsonString
import javax.json.Json; //导入依赖的package包/类
private static void parseJsonString() {
JsonParser parser = Json.createParser(new StringReader(JSON));
while (parser.hasNext()) {
JsonParser.Event event = parser.next();
switch (event) {
case START_ARRAY:
case END_ARRAY:
case START_OBJECT:
case END_OBJECT:
case VALUE_FALSE:
case VALUE_NULL:
case VALUE_TRUE:
System.out.println(event.toString());
break;
case KEY_NAME:
System.out.print(event.toString() + " " + parser.getString() + " - ");
break;
case VALUE_STRING:
case VALUE_NUMBER:
System.out.println(event.toString() + " " + parser.getString());
break;
}
}
}
示例2: onOpen
import javax.json.Json; //导入依赖的package包/类
@OnOpen
public void onOpen(Session session, @PathParam("uuid") String uuid) {
UUID key = UUID.fromString(uuid);
peers.put(key, session);
JsonArrayBuilder builder = Json.createArrayBuilder();
for (StatusEventType statusEventType : StatusEventType.values()) {
JsonObjectBuilder object = Json.createObjectBuilder();
builder.add(object.add(statusEventType.name(), statusEventType.getMessage()).build());
}
RemoteEndpoint.Async asyncRemote = session.getAsyncRemote();
asyncRemote.sendText(builder.build().toString());
// Send pending messages
List<String> messages = messageBuffer.remove(key);
if (messages != null) {
messages.forEach(asyncRemote::sendText);
}
}
示例3: verifyInjectedIssuer
import javax.json.Json; //导入依赖的package包/类
@GET
@Path("/verifyInjectedIssuer")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("Tester")
public JsonObject verifyInjectedIssuer(@QueryParam("iss") String iss) {
boolean pass = false;
String msg;
String issValue = issuer.getString();
if(issValue == null || issValue.length() == 0) {
msg = Claims.iss.name()+"value is null or empty, FAIL";
}
else if(issValue.equals(iss)) {
msg = Claims.iss.name()+" PASS";
pass = true;
}
else {
msg = String.format("%s: %s != %s", Claims.iss.name(), issValue, iss);
}
JsonObject result = Json.createObjectBuilder()
.add("pass", pass)
.add("msg", msg)
.build();
return result;
}
示例4: verifyInjectedIssuer
import javax.json.Json; //导入依赖的package包/类
@GET
@Path("/verifyInjectedIssuer")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedIssuer(@QueryParam("iss") String iss) {
boolean pass = false;
String msg;
String issValue = issuer.get();
if(issValue == null || issValue.length() == 0) {
msg = Claims.iss.name()+"value is null or empty, FAIL";
}
else if(issValue.equals(iss)) {
msg = Claims.iss.name()+" PASS";
pass = true;
}
else {
msg = String.format("%s: %s != %s", Claims.iss.name(), issValue, iss);
}
JsonObject result = Json.createObjectBuilder()
.add("pass", pass)
.add("msg", msg)
.build();
return result;
}
示例5: additionWithIncompleteInput
import javax.json.Json; //导入依赖的package包/类
@Test
public void additionWithIncompleteInput() {
JsonObject input = Json.createObjectBuilder().
add("b", 2).
build();
Response response = this.tut.
request(MediaType.APPLICATION_JSON).
post(json(input));
assertThat(response.getStatus(), is(400));
String cause = response.getHeaderString("cause");
assertThat(cause, containsString(" a "));
input = Json.createObjectBuilder().
add("a", 2).
build();
response = this.tut.
request(MediaType.APPLICATION_JSON).
post(json(input));
assertThat(response.getStatus(), is(400));
cause = response.getHeaderString("cause");
assertThat(cause, containsString(" b "));
}
示例6: find
import javax.json.Json; //导入依赖的package包/类
@GET
@Path("find")
@Produces(MediaType.APPLICATION_JSON)
public Response find() {
JsonArray build = null;
try {
build = religionService.get().stream().map(h -> Json.createObjectBuilder()
.add("id", h.getReligionId())
.add("name", h.getName())
.build())
.collect(Json::createArrayBuilder, JsonArrayBuilder::add, JsonArrayBuilder::add)
.build();
} catch (Exception ex) {
return Response.ok().header("Exception", ex.getMessage()).build();
}
return Response.ok().entity(build == null ? "No data found" : build).build();
}
示例7: verifyInjectedAudience
import javax.json.Json; //导入依赖的package包/类
@GET
@Path("/verifyInjectedAudience")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedAudience(@QueryParam("aud") String audience) {
boolean pass = false;
String msg;
// aud
Set<String> audValue = aud.get();
if(audValue == null || audValue.size() == 0) {
msg = Claims.aud.name()+"value is null or empty, FAIL";
}
else if(audValue.contains(audience)) {
msg = Claims.aud.name()+" PASS";
pass = true;
}
else {
msg = String.format("%s: %s != %s", Claims.aud.name(), audValue, audience);
}
JsonObject result = Json.createObjectBuilder()
.add("pass", pass)
.add("msg", msg)
.build();
return result;
}
示例8: verifyInjectedCustomDouble
import javax.json.Json; //导入依赖的package包/类
@GET
@Path("/verifyInjectedCustomDouble")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedCustomDouble(@QueryParam("value") Double value) {
boolean pass = false;
String msg;
// iat
JsonNumber customValue = customDouble.getValue();
if(customValue == null) {
msg = "customDouble value is null, FAIL";
}
else if(Math.abs(customValue.doubleValue() - value.doubleValue()) < 0.00001) {
msg = "customDouble PASS";
pass = true;
}
else {
msg = String.format("customDouble: %s != %.8f", customValue, value);
}
JsonObject result = Json.createObjectBuilder()
.add("pass", pass)
.add("msg", msg)
.build();
return result;
}
示例9: verifyIssuedAt
import javax.json.Json; //导入依赖的package包/类
@GET
@Path("/verifyIssuedAt")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyIssuedAt(@QueryParam("iat") Long iat) {
boolean pass = false;
String msg;
// iat
Long iatValue = rawTokenJson.getIssuedAtTime();
if (iatValue == null || iatValue.intValue() == 0) {
msg = Claims.iat.name() + "value is null or empty, FAIL";
}
else if (iatValue.equals(iat)) {
msg = Claims.iat.name() + " PASS";
pass = true;
}
else {
msg = String.format("%s: %s != %s", Claims.iat.name(), iatValue, iat);
}
JsonObject result = Json.createObjectBuilder()
.add("pass", pass)
.add("msg", msg)
.build();
return result;
}
示例10: verifyInjectedCustomDouble2
import javax.json.Json; //导入依赖的package包/类
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
description = "Verify that the injected customDouble claim is as expected")
public void verifyInjectedCustomDouble2() throws Exception {
Reporter.log("Begin verifyInjectedCustomDouble2\n");
String token2 = TokenUtils.generateTokenString("/Token2.json");
String uri = baseURL.toExternalForm() + "/endp/verifyInjectedCustomDouble";
WebTarget echoEndpointTarget = ClientBuilder.newClient()
.target(uri)
.queryParam("value", 3.241592653589793)
.queryParam(Claims.auth_time.name(), authTimeClaim);
Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token2).get();
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
JsonReader jsonReader = Json.createReader(new StringReader(replyString));
JsonObject reply = jsonReader.readObject();
Reporter.log(reply.toString());
Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
示例11: verifyInjectedJTI
import javax.json.Json; //导入依赖的package包/类
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
description = "Verify that the injected jti claim is as expected")
public void verifyInjectedJTI() throws Exception {
Reporter.log("Begin verifyInjectedJTI\n");
String uri = baseURL.toExternalForm() + "/endp/verifyInjectedJTI";
WebTarget echoEndpointTarget = ClientBuilder.newClient()
.target(uri)
.queryParam(Claims.jti.name(), "a-123")
.queryParam(Claims.auth_time.name(), authTimeClaim);
Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
JsonReader jsonReader = Json.createReader(new StringReader(replyString));
JsonObject reply = jsonReader.readObject();
Reporter.log(reply.toString());
Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
示例12: verifyIssuerClaim
import javax.json.Json; //导入依赖的package包/类
@RunAsClient
@Test(groups = TEST_GROUP_JWT,
description = "Verify that the token issuer claim is as expected")
public void verifyIssuerClaim() throws Exception {
Reporter.log("Begin verifyIssuerClaim");
String uri = baseURL.toExternalForm() + "/endp/verifyIssuer";
WebTarget echoEndpointTarget = ClientBuilder.newClient()
.target(uri)
.queryParam(Claims.iss.name(), TEST_ISSUER)
.queryParam(Claims.auth_time.name(), authTimeClaim);
Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
JsonReader jsonReader = Json.createReader(new StringReader(replyString));
JsonObject reply = jsonReader.readObject();
Reporter.log(reply.toString());
Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
示例13: verifyInjectedUPN
import javax.json.Json; //导入依赖的package包/类
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
description = "Verify that the injected upn claim is as expected")
public void verifyInjectedUPN() throws Exception {
Reporter.log("Begin verifyInjectedUPN\n");
String uri = baseURL.toExternalForm() + "/endp/verifyInjectedUPN";
WebTarget echoEndpointTarget = ClientBuilder.newClient()
.target(uri)
.queryParam(Claims.upn.name(), "[email protected]")
.queryParam(Claims.auth_time.name(), authTimeClaim);
Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
JsonReader jsonReader = Json.createReader(new StringReader(replyString));
JsonObject reply = jsonReader.readObject();
Reporter.log(reply.toString());
Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
示例14: verifyInjectedIssuedAtStandard
import javax.json.Json; //导入依赖的package包/类
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
description = "Verify that the injected iat claim using @Claim(standard) is as expected")
public void verifyInjectedIssuedAtStandard() throws Exception {
Reporter.log("Begin verifyInjectedIssuedAtStandard\n");
String uri = baseURL.toExternalForm() + "/endp/verifyInjectedIssuedAtStandard";
WebTarget echoEndpointTarget = ClientBuilder.newClient()
.target(uri)
.queryParam(Claims.iat.name(), iatClaim)
.queryParam(Claims.auth_time.name(), authTimeClaim);
Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
JsonReader jsonReader = Json.createReader(new StringReader(replyString));
JsonObject reply = jsonReader.readObject();
Reporter.log(reply.toString());
Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
示例15: getJsonObjectBuilder
import javax.json.Json; //导入依赖的package包/类
@Override
public JsonObjectBuilder getJsonObjectBuilder() {
JsonObjectBuilder jsonObjectBuilder =
Json.createObjectBuilder()
.add("transportId", this.transportId)
.add("localCandidateId", this.localCandidateId)
.add("remoteCandidateId", this.remoteCandidateId)
.add("state", this.state)
.add("priority", this.priority)
.add("nominated", this.nominated)
.add("bytesSent", this.bytesSent)
.add("currentRoundTripTime", this.currentRoundTripTime)
.add("totalRoundTripTime", this.totalRoundTripTime)
.add("bytesReceived", this.bytesReceived);
return jsonObjectBuilder;
}