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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations