Search in sources :

Example 26 with JsonStructure

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

the class RtPull method merge.

@Override
public void merge(final String msg) throws IOException {
    final JsonStructure json = Json.createObjectBuilder().add("commit_message", msg).build();
    this.merge(json).assertStatus(HttpURLConnection.HTTP_OK);
}
Also used : JsonStructure(javax.json.JsonStructure)

Example 27 with JsonStructure

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

the class AlignTestBase method assertJsonEqual.

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

Example 28 with JsonStructure

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

the class JsrJsonpProviderTest method testReadJsonArray.

@Test
public void testReadJsonArray() throws Exception {
    final StringWriter writer = new StringWriter();
    Json.createGenerator(writer).writeStartArray().write("Tom").write("Tommyknocker").writeEnd().close();
    final JsonStructure obj = provider.readFrom(JsonStructure.class, null, null, null, null, new ByteArrayInputStream(writer.toString().getBytes()));
    assertThat(obj, instanceOf(JsonArray.class));
    assertThat(((JsonArray) obj).getString(0), equalTo("Tom"));
    assertThat(((JsonArray) obj).getString(1), equalTo("Tommyknocker"));
    assertThat(((JsonArray) obj).size(), equalTo(2));
}
Also used : JsonArray(javax.json.JsonArray) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonStructure(javax.json.JsonStructure) Test(org.junit.Test)

Example 29 with JsonStructure

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

the class JsrJsonpProviderTest method testReadJsonObject.

@Test
public void testReadJsonObject() throws Exception {
    final StringWriter writer = new StringWriter();
    Json.createGenerator(writer).writeStartObject().write("firstName", "Tom").write("lastName", "Tommyknocker").writeEnd().close();
    final String str = writer.toString();
    writer.close();
    final JsonStructure obj = provider.readFrom(JsonStructure.class, null, null, null, null, new ByteArrayInputStream(str.getBytes()));
    assertThat(obj, instanceOf(JsonObject.class));
    assertThat(((JsonObject) obj).getString("firstName"), equalTo("Tom"));
    assertThat(((JsonObject) obj).getString("lastName"), equalTo("Tommyknocker"));
}
Also used : StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonObject(javax.json.JsonObject) JsonStructure(javax.json.JsonStructure) Test(org.junit.Test)

Example 30 with JsonStructure

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

the class Json2XmlValidator method alignJson.

protected PipeRunResult alignJson(String messageToValidate, PipeLineSession session, boolean responseMode) throws PipeRunException, XmlValidatorException {
    ValidationContext context;
    ValidatorHandler validatorHandler;
    try {
        context = validator.createValidationContext(session, getJsonRootValidations(responseMode), getInvalidRootNamespaces());
        validatorHandler = validator.getValidatorHandler(session, context);
    } catch (ConfigurationException e) {
        throw new PipeRunException(this, "Cannot create ValidationContext", e);
    }
    String resultEvent;
    String out = null;
    try {
        Json2Xml aligner = new Json2Xml(validatorHandler, context.getXsModels(), isCompactJsonArrays(), getMessageRoot(responseMode), isStrictJsonArraySyntax());
        if (StringUtils.isNotEmpty(getTargetNamespace())) {
            aligner.setTargetNamespace(getTargetNamespace());
        }
        aligner.setDeepSearch(isDeepSearch());
        aligner.setErrorHandler(context.getErrorHandler());
        aligner.setFailOnWildcards(isFailOnWildcards());
        aligner.setIgnoreUndeclaredElements(isIgnoreUndeclaredElements());
        ParameterList parameterList = getParameterList();
        if (parameterList != null) {
            Map<String, Object> parametervalues = null;
            parametervalues = parameterList.getValues(new Message(messageToValidate), session).getValueMap();
            // remove parameters with null values, to support optional request parameters
            for (Iterator<String> it = parametervalues.keySet().iterator(); it.hasNext(); ) {
                String key = it.next();
                if (parametervalues.get(key) == null) {
                    it.remove();
                }
            }
            aligner.setOverrideValues(parametervalues);
        }
        JsonStructure jsonStructure = Json.createReader(new StringReader(messageToValidate)).read();
        // cannot build filter chain as usual backwardly, because it ends differently.
        // This will be fixed once an OutputStream can be provided to Xml2Json
        XMLFilterImpl sourceFilter = aligner;
        if (StringUtils.isNotEmpty(getRootElementSessionKey())) {
            XMLFilterImpl storeRootFilter = new RootElementToSessionKeyFilter(session, getRootElementSessionKey(), getRootNamespaceSessionKey(), null);
            aligner.setContentHandler(storeRootFilter);
            sourceFilter = storeRootFilter;
        }
        if (getOutputFormat(session, responseMode) == DocumentFormat.JSON) {
            Xml2Json xml2json = new Xml2Json(aligner, isCompactJsonArrays(), !isJsonWithRootElements());
            sourceFilter.setContentHandler(xml2json);
            aligner.startParse(jsonStructure);
            out = xml2json.toString();
        } else {
            XmlWriter xmlWriter = new XmlWriter();
            xmlWriter.setIncludeXmlDeclaration(true);
            ContentHandler handler = xmlWriter;
            if (isProduceNamespaceLessXml()) {
                handler = new NamespaceRemovingFilter(handler);
            }
            sourceFilter.setContentHandler(handler);
            aligner.startParse(jsonStructure);
            out = xmlWriter.toString();
        }
    } catch (Exception e) {
        resultEvent = validator.finalizeValidation(context, session, e);
    }
    resultEvent = validator.finalizeValidation(context, session, null);
    PipeForward forward = determineForward(resultEvent, session, responseMode);
    PipeRunResult result = new PipeRunResult(forward, out);
    return result;
}
Also used : RootElementToSessionKeyFilter(nl.nn.adapterframework.xml.RootElementToSessionKeyFilter) ValidatorHandler(javax.xml.validation.ValidatorHandler) Message(nl.nn.adapterframework.stream.Message) PipeForward(nl.nn.adapterframework.core.PipeForward) ContentHandler(org.xml.sax.ContentHandler) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XmlValidatorException(nl.nn.adapterframework.validation.XmlValidatorException) ValidationContext(nl.nn.adapterframework.validation.ValidationContext) NamespaceRemovingFilter(nl.nn.adapterframework.xml.NamespaceRemovingFilter) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XMLFilterImpl(org.xml.sax.helpers.XMLFilterImpl) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StringReader(java.io.StringReader) ParameterList(nl.nn.adapterframework.parameters.ParameterList) JsonObject(javax.json.JsonObject) Xml2Json(nl.nn.adapterframework.align.Xml2Json) Json2Xml(nl.nn.adapterframework.align.Json2Xml) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) 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