private static final String API_VERSION = "1.0.0";
private static final String SWAGGER_VERSION = "2.0";
private static final String OPEN_API_VERSION = "3.0.3";
+ private static final ObjectMapper MAPPER = new ObjectMapper();
private final DefinitionGenerator jsonConverter = new DefinitionGenerator();
-
- private final ObjectMapper mapper = new ObjectMapper();
private final DOMSchemaService schemaService;
public static final String BASE_PATH = "/";
public static final String MODULE_NAME_SUFFIX = "_module";
+ static {
+ MAPPER.configure(SerializationFeature.INDENT_OUTPUT, true);
+ }
+
protected BaseYangSwaggerGenerator(final Optional<DOMSchemaService> schemaService) {
this.schemaService = schemaService.orElse(null);
- mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
}
public DOMSchemaService getSchemaService() {
addFields(doc.getDefinitions(), definitions.fields());
}
if (LOG.isDebugEnabled()) {
- LOG.debug("Document: {}", mapper.writeValueAsString(doc));
+ LOG.debug("Document: {}", MAPPER.writeValueAsString(doc));
}
} catch (final IOException e) {
LOG.error("Exception occured in DefinitionGenerator", e);
@Produces(MediaType.APPLICATION_JSON)
public class JaxbContextResolver implements ContextResolver<ObjectMapper> {
- private final ObjectMapper ctx;
-
- public JaxbContextResolver() {
- ctx = new ObjectMapper();
- }
+ private static final ObjectMapper CTX = new ObjectMapper();
@Override
public ObjectMapper getContext(final Class<?> klass) {
if (SwaggerObject.class.isAssignableFrom(klass)) {
- return ctx;
+ return CTX;
}
return null; // must return null so that JAX-RS can continue context search
.node(QName.create("", "nodes"))
.node(QName.create("", "node"))
.nodeWithKey(QName.create("", "node"), QName.create("", "id"), "123").build();
+ private static final ObjectMapper MAPPER = new ObjectMapper();
private ApiDocService apiDocService;
public void getListOfMounts() throws Exception {
final UriInfo mockInfo = DocGenTestHelper.createMockUriInfo(HTTP_URL);
// simulate the behavior of JacksonJaxbJsonProvider
- final ObjectMapper mapper = new ObjectMapper();
- final String result = mapper.writer().writeValueAsString(apiDocService.getListOfMounts(mockInfo).getEntity());
+ final String result = MAPPER.writer().writeValueAsString(apiDocService.getListOfMounts(mockInfo).getEntity());
assertEquals("[{\"instance\":\"/nodes/node=123/\",\"id\":1}]", result);
}
}