ExtendedQALDJSONLoader { public static void writeJson(final Object o, final File f, final boolean overwrite) throws IOException { if (f.exists() && !overwrite) { throw new IllegalArgumentException("File already exists. Set overwrite flag if you want to overwrite current file"); } ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); mapper.setSerializationInclusion(Include.NON_EMPTY); mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS); try { mapper.writerWithDefaultPrettyPrinter().writeValue(f, o); } catch (IOException e) { LOGGER.error("", e); } LOGGER.info("File Written to " + f.getAbsolutePath()); } private  ExtendedQALDJSONLoader(); static void writeJson(final Object o, final File f, final boolean overwrite); static byte[] writeJson(final Object json); static Object readJson(final byte[] inputJson, final Class<?> type); static Object readJson(final InputStream in, final Class<?> type); static Object readJson(final InputStream in); static Object readJson(final File f); static Object readJson(final File f, final Class<?> type);  }
@Test public void extentedJSONTest() throws JsonProcessingException { HashMap<String, EJBinding> hash = new HashMap<>(); hash.put("myVar", new EJBinding().setType("myType").setValue("myValue")); ExtendedJson ej = new ExtendedJson(); EJQuestionEntry entry = new EJQuestionEntry(); EJAnswers answers = new EJAnswers(); entry.getQuestion().addAnsweritemtype("answeritemtype").setId(5 + "").setAnswertype("someAnswertype").setConfidence("very confident").setAnswers(answers); answers.setHead(new EJHead()); answers.getHead().getVars().add("myVariable"); answers.getHead().getLink().add("http: EJResults results = new EJResults(); results.getBindings().add((hash)); answers.setResults(results); answers.setConfidence("so confident, very satisfied, such unafraid").setBoolean(true); EJDataset dataset = new EJDataset(); dataset.setId("5").setMetadata("MetadataString"); ej.setDataset(dataset); ej.addQuestions(entry); String content = new String(ExtendedQALDJSONLoader.writeJson(ej)); String realContent = "{\"dataset\":{\"id\":\"5\",\"metadata\":\"MetadataString\"},\"questions\":[{\"question\":{\"id\":\"5\",\"answertype\":\"someAnswertype\",\"" + "confidence\":\"very confident\",\"answeritemtype\":[\"answeritemtype\"],\"answers\":{\"head\":{\"vars\":[\"myVariable\"],\"link\":[\"http: + "{\"bindings\":[{\"myVar\":{\"type\":\"myType\",\"value\":\"myValue\"}}]},\"confidence\":\"so confident, very satisfied, such unafraid\",\"boolean\":true}}}]}"; Assert.assertTrue(realContent.equals(content)); }