Search in sources :

Example 21 with JsonStructure

use of javax.json.JsonStructure in project iaf by ibissource.

the class JsonXsltPipeTest method assertJsonEqual.

public void assertJsonEqual(String description, String jsonExp, String jsonAct) {
    JsonStructure jExp = string2Json(jsonExp);
    log.debug("jsonAct: [" + jsonAct + "]");
    JsonStructure jAct = string2Json(jsonAct);
    assertEquals(description, jExp.toString(), jAct.toString());
// assertEquals(description,inputJson,jsonOut);
}
Also used : JsonStructure(javax.json.JsonStructure)

Example 22 with JsonStructure

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

the class JsonProcessingTest method testJsonStructureObject.

@Test
public void testJsonStructureObject() throws Exception {
    final Response response = target("jsonStructure").request(MediaType.APPLICATION_JSON).post(Entity.json(JSON_OBJECT));
    assertEquals(JSON_OBJECT, response.readEntity(JsonStructure.class));
}
Also used : Response(javax.ws.rs.core.Response) JsonStructure(javax.json.JsonStructure) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 23 with JsonStructure

use of javax.json.JsonStructure in project sling by apache.

the class JsonPipe method getOutput.

/**
     * in case there is no successful retrieval of some JSON data, we cut the pipe here
     * @return input resource of the pipe, can be reouputed N times in case output json binding is an array of
     * N element (output binding would be here each time the Nth element of the array)
     */
public Iterator<Resource> getOutput() {
    Iterator<Resource> output = EMPTY_ITERATOR;
    binding = null;
    String jsonString = retrieveJSONString();
    if (StringUtils.isNotBlank(jsonString)) {
        try {
            JsonStructure json;
            try {
                json = JsonUtil.parse(jsonString);
            } catch (JsonException ex) {
                json = null;
            }
            if (json == null) {
                binding = jsonString.trim();
                output = super.getOutput();
            } else if (json.getValueType() != ValueType.ARRAY) {
                binding = JsonUtil.unbox(json);
                output = super.getOutput();
            } else {
                binding = array = (JsonArray) json;
                index = 0;
                output = new Iterator<Resource>() {

                    @Override
                    public boolean hasNext() {
                        return index < array.size();
                    }

                    @Override
                    public Resource next() {
                        try {
                            binding = JsonUtil.unbox(array.get(index));
                        } catch (Exception e) {
                            logger.error("Unable to retrieve {}nth item of jsonarray", index, e);
                        }
                        index++;
                        return getInput();
                    }
                };
            }
        } catch (JsonException e) {
            logger.error("unable to parse JSON {} ", jsonString, e);
        }
    }
    return output;
}
Also used : JsonException(javax.json.JsonException) Resource(org.apache.sling.api.resource.Resource) Iterator(java.util.Iterator) JsonException(javax.json.JsonException) JsonStructure(javax.json.JsonStructure)

Example 24 with JsonStructure

use of javax.json.JsonStructure in project felix by apache.

the class TypeConverter method getConverter.

public static Converter getConverter() {
    return Converters.standardConverter().newConverterBuilder().rule(new TargetRule() {

        @Override
        public Type getTargetType() {
            return String.class;
        }

        @Override
        public ConverterFunction getFunction() {
            return new ConverterFunction() {

                @Override
                public Object apply(final Object obj, final Type targetType) throws Exception {
                    if (obj instanceof Map || obj instanceof List) {
                        final JsonStructure json = JSONUtil.build(obj);
                        final StringWriter w = new StringWriter();
                        Json.createWriter(w).write(json);
                        return w.toString();
                    }
                    return CANNOT_HANDLE;
                }
            };
        }
    }).build();
}
Also used : Type(java.lang.reflect.Type) StringWriter(java.io.StringWriter) ConverterFunction(org.osgi.util.converter.ConverterFunction) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TargetRule(org.osgi.util.converter.TargetRule) JsonStructure(javax.json.JsonStructure)

Example 25 with JsonStructure

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

the class RtIssueLabels method replace.

@Override
public void replace(final Iterable<String> labels) throws IOException {
    JsonArrayBuilder builder = Json.createArrayBuilder();
    for (final String label : labels) {
        builder = builder.add(label);
    }
    final JsonStructure json = builder.build();
    this.request.method(Request.PUT).body().set(json).back().fetch().as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_OK).as(JsonResponse.class).json().readArray();
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonStructure(javax.json.JsonStructure)

Aggregations

JsonStructure (javax.json.JsonStructure)37 JsonObject (javax.json.JsonObject)14 StringReader (java.io.StringReader)7 JsonObjectBuilder (javax.json.JsonObjectBuilder)5 Test (org.junit.Test)5 StringWriter (java.io.StringWriter)4 URL (java.net.URL)4 JsonArrayBuilder (javax.json.JsonArrayBuilder)4 IOException (java.io.IOException)3 Map (java.util.Map)3 JsonReader (javax.json.JsonReader)3 JsonString (javax.json.JsonString)3 PipeForward (nl.nn.adapterframework.core.PipeForward)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 HashMap (java.util.HashMap)2 List (java.util.List)2 JsonArray (javax.json.JsonArray)2 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)2 Message (nl.nn.adapterframework.stream.Message)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1