Search in sources :

Example 31 with JsonStructure

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

the class Json2XmlValidator method createJsonSchema.

public JsonStructure createJsonSchema(String elementName, String namespace) {
    List<XSModel> models = validator.getXSModels();
    XmlTypeToJsonSchemaConverter converter = new XmlTypeToJsonSchemaConverter(models, isCompactJsonArrays(), !isJsonWithRootElements(), getSchemaLocation());
    JsonStructure jsonschema = converter.createJsonSchema(elementName, namespace);
    return jsonschema;
}
Also used : XmlTypeToJsonSchemaConverter(nl.nn.adapterframework.align.XmlTypeToJsonSchemaConverter) XSModel(org.apache.xerces.xs.XSModel) JsonStructure(javax.json.JsonStructure)

Example 32 with JsonStructure

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

the class TestJson2Xml method testTreeAndMap.

public void testTreeAndMap(String schemaFile, String namespace, String rootElement, String inputFile, String resultFile, String expectedFailureReason) throws Exception {
    URL schemaUrl = getSchemaURL(schemaFile);
    String xmlString = getTestFile(inputFile + ".xml");
    String jsonString = getTestFile(inputFile + ".json");
    String propertiesString = getTestFile(inputFile + ".properties");
    String resultJsonString = getTestFile(resultFile + ".json");
    JsonStructure jsonIn = Utils.string2Json(jsonString);
    System.out.println("jsonIn [" + jsonIn + "]");
    Map<String, Object> map = MatchUtils.stringToMap(propertiesString);
    testJson(jsonString, map, true, schemaUrl, namespace, rootElement, true, false, resultJsonString, expectedFailureReason, null);
// String schemaString=FileUtils.resourceToString(schemaUrl);
}
Also used : JsonObject(javax.json.JsonObject) URL(java.net.URL) JsonStructure(javax.json.JsonStructure)

Example 33 with JsonStructure

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

the class TestXml2Map method testFiles.

@Override
public void testFiles(String schemaFile, String namespace, String rootElement, String inputFile, boolean potentialCompactionProblems, String expectedFailureReason) throws Exception {
    URL schemaUrl = getSchemaURL(schemaFile);
    String xmlString = getTestFile(inputFile + ".xml");
    String mapString = getTestFile(inputFile + ".properties");
    boolean expectValid = expectedFailureReason == null;
    // check the validity of the input XML
    assertEquals("valid XML", expectValid, Utils.validate(schemaUrl, xmlString));
    System.out.println("input xml:" + xmlString);
    JsonStructure json;
    Map<String, String> result;
    try {
        result = Xml2Map.translate(xmlString, schemaUrl);
        for (String key : result.keySet()) {
            String value = result.get(key);
            System.out.println(key + "=" + value);
        }
        if (!expectValid) {
            fail("expected to fail");
        }
        if (mapString == null) {
            fail("no .properties file for [" + inputFile + "]!");
        }
        assertEquals(mapString.trim(), MatchUtils.mapToString(result).trim());
    } catch (Exception e) {
        if (expectValid) {
            e.printStackTrace();
            fail(e.getMessage());
        }
        return;
    }
}
Also used : URL(java.net.URL) JsonStructure(javax.json.JsonStructure)

Example 34 with JsonStructure

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

the class JsonXsltSenderTest 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 35 with JsonStructure

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

the class XmlTypeToJsonSchemaConverter method buildSkippableArrayContainer.

private void buildSkippableArrayContainer(XSParticle childParticle, JsonObjectBuilder builder) {
    JsonObjectBuilder refBuilder = Json.createObjectBuilder();
    handleParticle(refBuilder, childParticle, null, false);
    XSTerm childTerm = childParticle.getTerm();
    if (childTerm instanceof XSElementDeclaration) {
        XSElementDeclaration elementDeclaration = (XSElementDeclaration) childTerm;
        XSTypeDefinition elementTypeDefinition = elementDeclaration.getTypeDefinition();
        JsonStructure definition = getDefinition(elementTypeDefinition, true);
        builder.add("type", "array");
        if (elementDeclaration.getNillable()) {
            definition = nillable(definition);
        }
        builder.add("items", definition);
    }
}
Also used : XSTypeDefinition(org.apache.xerces.xs.XSTypeDefinition) XSTerm(org.apache.xerces.xs.XSTerm) XSElementDeclaration(org.apache.xerces.xs.XSElementDeclaration) JsonObjectBuilder(javax.json.JsonObjectBuilder) 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