JsonTools { public ObjectMapper getObjectMapper() { return getObjectMapper(outputType); } JsonTools(FileUtils fileUtils); ObjectMapper getObjectMapper(); ObjectWriter getObjectWriter(); ObjectWriter getObjectWriter(String outputType); ObjectMapper getObjectMapper(final String type); File getDocumentFile(final File rootDir, final String fileName); T readDocumentFile(final File file, final JavaType entityMapType); T readStream(final InputStream stream, final String type, final JavaType entityMapType); @NotNull String getTypeFromFile(File file); @Nullable String getTypeFromExtension(String extension); void setOutputType(String outputType); String getFileExtension(); void writeObject(final Object object, OutputStream outputStream); static final JsonTools INSTANCE; static final String JSON; static final String YAML; static final String JSON_EXTENSION; static final String YML_EXTENSION; static final String YAML_EXTENSION; }
@Test void getObjectMapper() { assertNotNull(jsonTools.getObjectMapper()); assertTrue(jsonTools.getObjectMapper().getFactory() instanceof YAMLFactory); jsonTools.setOutputType(JsonTools.JSON); assertFalse(jsonTools.getObjectMapper().getFactory() instanceof YAMLFactory); assertTrue(jsonTools.getObjectMapper(JsonTools.YAML).getFactory() instanceof YAMLFactory); assertFalse(jsonTools.getObjectMapper(JsonTools.JSON).getFactory() instanceof YAMLFactory); assertThrows(IllegalArgumentException.class, () -> jsonTools.getObjectMapper("xyz")); assertFalse(jsonTools.getObjectMapper(JsonTools.YAML).getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); assertFalse(jsonTools.getObjectMapper(JsonTools.YAML).getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY)); assertFalse(jsonTools.getObjectMapper(JsonTools.JSON).getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); assertFalse(jsonTools.getObjectMapper(JsonTools.JSON).getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY)); }