Search in sources :

Example 61 with JsonString

use of javax.json.JsonString in project traccar by traccar.

the class FlespiProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    HttpRequest request = (HttpRequest) msg;
    JsonArray result = Json.createReader(new StringReader(request.getContent().toString(StandardCharsets.UTF_8))).readArray();
    List<Position> positions = new LinkedList<>();
    for (int i = 0; i < result.size(); i++) {
        JsonObject message = result.getJsonObject(i);
        JsonString ident = message.getJsonString("ident");
        if (ident == null) {
            continue;
        }
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ident.getString());
        if (deviceSession == null) {
            continue;
        }
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        decodePosition(message, position);
        positions.add(position);
    }
    sendResponse(channel, HttpResponseStatus.OK);
    return positions;
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) JsonArray(javax.json.JsonArray) DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) LinkedList(java.util.LinkedList)

Example 62 with JsonString

use of javax.json.JsonString in project jcabi-github by jcabi.

the class MkReleaseTest method value.

/**
 * Returns string property value.
 * @param release Release
 * @param name Property name
 * @return Value as a string
 * @throws IOException If some problem inside
 */
private String value(final Release release, final String name) throws IOException {
    final JsonValue jsonValue = release.json().get(name);
    String result = null;
    if (jsonValue instanceof JsonString) {
        result = ((JsonString) jsonValue).getString();
    }
    return result;
}
Also used : JsonValue(javax.json.JsonValue) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString)

Example 63 with JsonString

use of javax.json.JsonString in project traccar by tananaev.

the class FlespiProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    FullHttpRequest request = (FullHttpRequest) msg;
    JsonArray result = Json.createReader(new StringReader(request.content().toString(StandardCharsets.UTF_8))).readArray();
    List<Position> positions = new LinkedList<>();
    for (int i = 0; i < result.size(); i++) {
        JsonObject message = result.getJsonObject(i);
        JsonString ident = message.getJsonString("ident");
        if (ident == null) {
            continue;
        }
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ident.getString());
        if (deviceSession == null) {
            continue;
        }
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        position.setValid(true);
        decodePosition(message, position);
        positions.add(position);
    }
    sendResponse(channel, HttpResponseStatus.OK);
    return positions;
}
Also used : JsonArray(javax.json.JsonArray) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) LinkedList(java.util.LinkedList)

Example 64 with JsonString

use of javax.json.JsonString in project traccar by tananaev.

the class GoogleGeocoder method parseAddress.

@Override
public Address parseAddress(JsonObject json) {
    JsonArray results = json.getJsonArray("results");
    if (!results.isEmpty()) {
        Address address = new Address();
        JsonObject result = (JsonObject) results.get(0);
        JsonArray components = result.getJsonArray("address_components");
        if (result.containsKey("formatted_address")) {
            address.setFormattedAddress(result.getString("formatted_address"));
        }
        for (JsonObject component : components.getValuesAs(JsonObject.class)) {
            String value = component.getString("short_name");
            typesLoop: for (JsonString type : component.getJsonArray("types").getValuesAs(JsonString.class)) {
                switch(type.getString()) {
                    case "street_number":
                        address.setHouse(value);
                        break typesLoop;
                    case "route":
                        address.setStreet(value);
                        break typesLoop;
                    case "locality":
                        address.setSettlement(value);
                        break typesLoop;
                    case "administrative_area_level_2":
                        address.setDistrict(value);
                        break typesLoop;
                    case "administrative_area_level_1":
                        address.setState(value);
                        break typesLoop;
                    case "country":
                        address.setCountry(value);
                        break typesLoop;
                    case "postal_code":
                        address.setPostcode(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 65 with JsonString

use of javax.json.JsonString in project opentheso by miledrousset.

the class ArkClientRest method isExist.

private boolean isExist(String jsonResponse) {
    if (jsonResponse == null)
        return false;
    JsonReader reader = Json.createReader(new StringReader(jsonResponse));
    JsonObject jsonObject = reader.readObject();
    reader.close();
    JsonString values = jsonObject.getJsonString("description");
    if (values != null) {
        if (values.getString().contains("Inexistant ARK"))
            return false;
        else if (values.getString().contains("Ark retreived"))
            return true;
    }
    return false;
}
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