Search in sources :

Example 31 with JsonString

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;
}
Also used : JsonArray(javax.json.JsonArray) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString)

Example 32 with JsonString

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;
}
Also used : JsonArray(javax.json.JsonArray) JsonNumber(javax.json.JsonNumber) JsonValue(javax.json.JsonValue) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString) JsonObjectBuilder(javax.json.JsonObjectBuilder) Map(java.util.Map)

Example 33 with JsonString

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);
}
Also used : TestMessageBodyReader(org.eclipse.microprofile.rest.client.tck.providers.TestMessageBodyReader) TestWriterInterceptor(org.eclipse.microprofile.rest.client.tck.providers.TestWriterInterceptor) AsyncClientWithCompletionStage(org.apache.cxf.systest.microprofile.rest.client.mock.AsyncClientWithCompletionStage) JsonObject(javax.json.JsonObject) TestClientRequestFilter(org.eclipse.microprofile.rest.client.tck.providers.TestClientRequestFilter) TestParamConverterProvider(org.eclipse.microprofile.rest.client.tck.providers.TestParamConverterProvider) JsonString(javax.json.JsonString) JsonStructure(javax.json.JsonStructure) Test(org.junit.Test)

Example 34 with JsonString

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);
}
Also used : TestMessageBodyReader(org.eclipse.microprofile.rest.client.tck.providers.TestMessageBodyReader) TestWriterInterceptor(org.eclipse.microprofile.rest.client.tck.providers.TestWriterInterceptor) AsyncClientWithCompletionStage(org.apache.cxf.systest.microprofile.rest.client.mock.AsyncClientWithCompletionStage) Collection(java.util.Collection) JsonObject(javax.json.JsonObject) TestClientRequestFilter(org.eclipse.microprofile.rest.client.tck.providers.TestClientRequestFilter) TestParamConverterProvider(org.eclipse.microprofile.rest.client.tck.providers.TestParamConverterProvider) JsonString(javax.json.JsonString) Test(org.junit.Test)

Example 35 with JsonString

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;
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString)

Aggregations

JsonString (javax.json.JsonString)78 JsonObject (javax.json.JsonObject)54 JsonReader (javax.json.JsonReader)36 StringReader (java.io.StringReader)34 Test (org.junit.Test)30 JsonArray (javax.json.JsonArray)24 HashMap (java.util.HashMap)17 JsonValue (javax.json.JsonValue)16 LinkedList (java.util.LinkedList)10 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 JsonNumber (javax.json.JsonNumber)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 JsonException (javax.json.JsonException)5 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)5 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)5 RemoteProcessGroupStatus (org.apache.nifi.controller.status.RemoteProcessGroupStatus)5 POST (javax.ws.rs.POST)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3