use of javax.json.JsonString in project traccar by tananaev.
the class MapboxGeocoder method parseAddress.
@Override
public Address parseAddress(JsonObject json) {
JsonArray features = json.getJsonArray("features");
if (!features.isEmpty()) {
Address address = new Address();
JsonObject mostSpecificFeature = (JsonObject) features.get(0);
if (mostSpecificFeature.containsKey("place_name")) {
address.setFormattedAddress(mostSpecificFeature.getString("place_name"));
}
if (mostSpecificFeature.containsKey("address")) {
address.setHouse(mostSpecificFeature.getString("address"));
}
for (JsonObject feature : features.getValuesAs(JsonObject.class)) {
String value = feature.getString("text");
typesLoop: for (JsonString type : feature.getJsonArray("place_type").getValuesAs(JsonString.class)) {
switch(type.getString()) {
case "address":
address.setStreet(value);
break typesLoop;
case "neighborhood":
address.setSuburb(value);
break typesLoop;
case "postcode":
address.setPostcode(value);
break typesLoop;
case "locality":
address.setSettlement(value);
break typesLoop;
case "district":
case "place":
address.setDistrict(value);
break typesLoop;
case "region":
address.setState(value);
break typesLoop;
case "country":
address.setCountry(value);
break typesLoop;
default:
break;
}
}
}
return address;
}
return null;
}
use of javax.json.JsonString in project knime-core by knime.
the class OpenAPIDefinitionGenerator method translateToSchema.
/**
* Translates a {@link JsonValue} into a json-schema/open-api-schema.
*
* @param v the json value
* @return the resulting json
*/
private static JsonObjectBuilder translateToSchema(final JsonValue v) {
final JsonObjectBuilder node = Json.createObjectBuilder();
if (v instanceof JsonObject) {
node.add("type", "object");
final JsonObjectBuilder properties = Json.createObjectBuilder();
for (Map.Entry<String, JsonValue> e : ((JsonObject) v).entrySet()) {
final JsonObjectBuilder child = translateToSchema(e.getValue());
properties.add(e.getKey(), child);
}
node.add("properties", properties);
} else if (v instanceof JsonNumber) {
final JsonNumber number = (JsonNumber) v;
if (number.isIntegral()) {
node.add("type", "integer");
node.add("default", number.longValue());
} else {
node.add("type", "number");
node.add("default", number.doubleValue());
}
} else if (v instanceof JsonString) {
node.add("type", "string");
node.add("default", ((JsonString) v).getString());
} else if ((v.getValueType() == ValueType.FALSE) || (v.getValueType() == ValueType.TRUE)) {
node.add("type", "boolean");
node.add("default", v.toString());
} else if (v instanceof JsonArray) {
node.add("type", "array");
if (!((JsonArray) v).isEmpty()) {
JsonObjectBuilder child = translateToSchema(((JsonArray) v).get(0));
node.add("items", child);
}
}
return node;
}
use of javax.json.JsonString in project cxf by apache.
the class AsyncMethodTest method testInvokesGetOperationWithRegisteredProvidersAsyncCompletionStage.
@Test
public void testInvokesGetOperationWithRegisteredProvidersAsyncCompletionStage() throws Exception {
wireMockRule.stubFor(get(urlEqualTo("/echo/test2")).willReturn(aResponse().withBody("{\"name\": \"test\"}")));
AsyncClientWithCompletionStage api = RestClientBuilder.newBuilder().register(TestClientRequestFilter.class).register(TestClientResponseFilter.class).register(TestMessageBodyReader.class, 3).register(TestMessageBodyWriter.class).register(TestParamConverterProvider.class).register(TestReaderInterceptor.class).register(TestWriterInterceptor.class).register(JsrJsonpProvider.class).baseUri(getBaseUri()).build(AsyncClientWithCompletionStage.class);
CompletionStage<JsonStructure> cs = api.get();
// should need <1 second, but 20s timeout in case something goes wrong
JsonStructure response = cs.toCompletableFuture().get(20, TimeUnit.SECONDS);
assertThat(response, instanceOf(JsonObject.class));
final JsonObject jsonObject = (JsonObject) response;
assertThat(jsonObject.get("name"), instanceOf(JsonString.class));
assertThat(((JsonString) jsonObject.get("name")).getString(), equalTo("test"));
assertEquals(TestClientResponseFilter.getAndResetValue(), 1);
assertEquals(TestClientRequestFilter.getAndResetValue(), 1);
assertEquals(TestReaderInterceptor.getAndResetValue(), 1);
}
use of javax.json.JsonString in project cxf by apache.
the class AsyncMethodTest method testInvokesGetAllOperationWithRegisteredProvidersAsyncCompletionStage.
@Test
public void testInvokesGetAllOperationWithRegisteredProvidersAsyncCompletionStage() throws Exception {
wireMockRule.stubFor(get(urlEqualTo("/echo/test3")).willReturn(aResponse().withBody("[{\"name\": \"test\"}]")));
AsyncClientWithCompletionStage api = RestClientBuilder.newBuilder().register(TestClientRequestFilter.class).register(TestClientResponseFilter.class).register(TestMessageBodyReader.class, 3).register(TestMessageBodyWriter.class).register(TestParamConverterProvider.class).register(TestReaderInterceptor.class).register(TestWriterInterceptor.class).register(JsrJsonpProvider.class).baseUri(getBaseUri()).build(AsyncClientWithCompletionStage.class);
CompletionStage<Collection<JsonObject>> cs = api.getAll();
// should need <1 second, but 20s timeout in case something goes wrong
Collection<JsonObject> response = cs.toCompletableFuture().get(20, TimeUnit.SECONDS);
assertEquals(1, response.size());
final JsonObject jsonObject = response.iterator().next();
assertThat(jsonObject.get("name"), instanceOf(JsonString.class));
assertThat(((JsonString) jsonObject.get("name")).getString(), equalTo("test"));
assertEquals(TestClientResponseFilter.getAndResetValue(), 1);
assertEquals(TestClientRequestFilter.getAndResetValue(), 1);
assertEquals(TestReaderInterceptor.getAndResetValue(), 1);
}
use of javax.json.JsonString in project opentheso by miledrousset.
the class ArkRestTests method getIArk.
private String getIArk(String jsonText) {
// {"responseCode":1,"handle":"20.500.11942/opentheso443"}
JsonReader reader = Json.createReader(new StringReader(jsonText));
JsonObject jsonObject = reader.readObject();
reader.close();
JsonString values = jsonObject.getJsonString("idArk");
if (values != null)
return values.getString();
/* for (int i = 0; i < values.size(); i++) {
JsonObject item = values.getJsonObject(i);
try {
idHandle = item.getString("nb_notices");
}
catch (JsonException e) {
System.out.println(e.toString());
}
catch (Exception ex) {
System.out.println(ex.toString());
}
}*/
return null;
}
Aggregations