Search in sources :

Example 36 with JsonString

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

the class HandleClient method getIdHandle.

private String getIdHandle(String jsonText) {
    if (jsonText == null)
        return null;
    // {"responseCode":1,"handle":"20.500.11942/opentheso443"}
    JsonReader reader = Json.createReader(new StringReader(jsonText));
    JsonObject jsonObject = reader.readObject();
    reader.close();
    JsonString values = jsonObject.getJsonString("handle");
    if (values != null)
        return values.getString();
    return null;
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString)

Example 37 with JsonString

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

the class ArkClientRest method setIdArkHandle.

private boolean setIdArkHandle() {
    if (jsonArk == null)
        return false;
    JsonReader reader = Json.createReader(new StringReader(jsonArk));
    JsonObject jsonObject = reader.readObject();
    reader.close();
    JsonString values = jsonObject.getJsonString("Ark");
    if (values == null)
        idArk = null;
    else
        idArk = values.getString().trim();
    values = jsonObject.getJsonString("Handle");
    if (values == null)
        idHandle = null;
    else
        idHandle = values.getString().trim();
    loginJson.put("token", jsonObject.getJsonString("token"));
    return true;
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString)

Example 38 with JsonString

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

the class DocumentFilteringResource method filter.

@POST
public JsonArray filter(final JsonArray properties) {
    final JsonArrayBuilder documents = Json.createArrayBuilder();
    final List<JsonString> propertyList = properties.getValuesAs(JsonString.class);
    for (final JsonObject jsonObject : DocumentStorage.getAll()) {
        final JsonObjectBuilder documentBuilder = Json.createObjectBuilder();
        for (final JsonString property : propertyList) {
            final String key = property.getString();
            if (jsonObject.containsKey(key)) {
                documentBuilder.add(key, jsonObject.get(key));
            }
        }
        final JsonObject document = documentBuilder.build();
        if (!document.isEmpty()) {
            documents.add(document);
        }
    }
    return documents.build();
}
Also used : JsonObject(javax.json.JsonObject) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString) JsonObjectBuilder(javax.json.JsonObjectBuilder) POST(javax.ws.rs.POST)

Example 39 with JsonString

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

the class TableRefConverter method fromJsonArray.

public static TableRef fromJsonArray(TableRefFactory tableRefFactory, JsonArray tableRefJsonArray) {
    TableRef tableRef = tableRefFactory.createRoot();
    for (JsonValue tableRefNameValue : tableRefJsonArray) {
        String tableRefName = ((JsonString) tableRefNameValue).getString();
        tableRef = createChild(tableRefFactory, tableRef, tableRefName);
    }
    return tableRef;
}
Also used : JsonValue(javax.json.JsonValue) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString) TableRef(com.torodb.core.TableRef)

Example 40 with JsonString

use of javax.json.JsonString in project azure-iot-sdk-java by Azure.

the class ToolsTest method getValueFromJsonObject_input_key_empty.

// Tests_SRS_SERVICE_SDK_JAVA_TOOLS_12_010: [The function shall return empty string if any of the input is null]
@Test
public void getValueFromJsonObject_input_key_empty() {
    // Arrange
    String jsonString = "{\"deviceId\":\"xxx-device\",\"generationId\":\"111111111111111111\",\"etag\":\"MA==\",\"connectionState\":\"Disconnected\",\"status\":\"disabled\",\"statusReason\":null,\"connectionStateUpdatedTime\":\"0001-01-01T00:00:00\",\"statusUpdatedTime\":\"0001-01-01T00:00:00\",\"lastActivityTime\":\"0001-01-01T00:00:00\",\"cloudToDeviceMessageCount\":0,\"authentication\":{\"symmetricKey\":{\"primaryKey\":\"AAABBBCCC111222333444000\",\"secondaryKey\":\"111222333444555AAABBBCCC\"}}}";
    StringReader stringReader = new StringReader(jsonString);
    JsonReader jsonReader = Json.createReader(stringReader);
    JsonObject jsonObject = jsonReader.readObject();
    String key = "";
    String expResult = "";
    // Act
    String result = Tools.getValueFromJsonObject(jsonObject, key);
    // Assert
    assertEquals(expResult, result);
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) Test(org.junit.Test)

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