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