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