List of usage examples for com.fasterxml.jackson.databind ObjectMapper enable
public ObjectMapper enable(SerializationFeature f)
From source file:org.jfrog.hudson.release.ReleaseAction.java
/** * This method is used to initiate a release staging process using the Artifactory Release Staging API. *///w w w . j a va 2s. co m @SuppressWarnings({ "UnusedDeclaration" }) protected void doApi(StaplerRequest req, StaplerResponse resp) throws IOException, ServletException { try { log.log(Level.INFO, "Initiating Artifactory Release Staging using API"); // Enforce release permissions project.checkPermission(ArtifactoryPlugin.RELEASE); // In case a staging user plugin is configured, the init() method invoke it: init(); // Read the values provided by the staging user plugin and assign them to data members in this class. // Those values can be overriden by URL arguments sent with the API: readStagingPluginValues(); // Read values from the request and override the staging plugin values: overrideStagingPluginParams(req); // Schedule the release build: if (!project.scheduleBuild(0, new Cause.UserIdCause(), this)) { log.log(Level.SEVERE, "Failed to schedule a release build following a Release API invocation"); resp.setStatus(StaplerResponse.SC_INTERNAL_SERVER_ERROR); } } catch (Exception e) { log.log(Level.SEVERE, "Artifactory Release Staging API invocation failed: " + e.getMessage(), e); resp.setStatus(StaplerResponse.SC_INTERNAL_SERVER_ERROR); ErrorResponse errorResponse = new ErrorResponse(StaplerResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); resp.getWriter().write(mapper.writeValueAsString(errorResponse)); } }
From source file:org.pentaho.metaverse.impl.model.ExecutionProfileUtil.java
public static void outputExecutionProfile(OutputStream outputStream, IExecutionProfile executionProfile) throws IOException { PrintStream out = null;//from www .j a v a 2 s . co m try { if (outputStream instanceof PrintStream) { out = (PrintStream) outputStream; } else { out = new PrintStream(outputStream); } ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.enable(SerializationFeature.WRAP_EXCEPTIONS); try { out.println(mapper.writeValueAsString(executionProfile)); } catch (JsonProcessingException jpe) { throw new IOException(jpe); } } finally { IOUtils.closeQuietly(out); } }
From source file:org.sosy_lab.cpachecker.appengine.server.resource.TasksServerResource.java
@Override public Representation tasksAsJson() { int offset = 0; if (getQueryValue("offset") != null) { offset = Integer.parseInt(getQueryValue("offset")); }// w w w. j a v a 2 s . co m if (offset < 0) { offset = 0; } int limit = -1; if (getQueryValue("limit") != null) { limit = Integer.parseInt(getQueryValue("limit")); } ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.addMixInAnnotations(Task.class, TaskMixinAnnotations.Minimal.class); try { return new StringRepresentation(mapper.writeValueAsString(TaskDAO.tasks(offset, limit)), MediaType.APPLICATION_JSON); } catch (JsonProcessingException e) { return null; } }
From source file:org.versly.rest.wsdoc.AnnotationProcessor.java
String jsonSchemaFromTypeMirror(TypeMirror type) { String serializedSchema = null; if (type.getKind().isPrimitive() || type.getKind() == TypeKind.VOID) { return null; }//from ww w. ja va 2s. co m // we need the dto class to generate schema using jackson json-schema module // note: Types.erasure() provides canonical names whereas Class.forName() wants a "regular" name, // so forName will fail for nested and inner classes as "regular" names use $ between parent and child. Class dtoClass = null; StringBuffer erasure = new StringBuffer(_typeUtils.erasure(type).toString()); for (boolean done = false; !done;) { try { dtoClass = Class.forName(erasure.toString()); done = true; } catch (ClassNotFoundException e) { if (erasure.lastIndexOf(".") != -1) { erasure.setCharAt(erasure.lastIndexOf("."), '$'); } else { done = true; } } } // if we were able to figure out the dto class, use jackson json-schema module to serialize it Exception e = null; if (dtoClass != null) { try { ObjectMapper m = new ObjectMapper(); m.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); m.registerModule(new JodaModule()); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); m.acceptJsonFormatVisitor(m.constructType(dtoClass), visitor); serializedSchema = m.writeValueAsString(visitor.finalSchema()); } catch (Exception ex) { e = ex; } } // report warning if we were not able to generate schema for non-primitive type if (serializedSchema == null) { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "cannot generate json-schema for class " + type.toString() + " (erasure " + erasure + "), " + ((e != null) ? ("exception: " + e.getMessage()) : "class not found")); } return serializedSchema; }
From source file:org.wso2.carbon.apimgt.impl.definitions.APIDefinitionUsingOASParser.java
/** * Creates a json string using the swagger object. * * @param swaggerObj swagger object//from w ww . j a va 2 s .c o m * @return json string using the swagger object * @throws APIManagementException error while creating swagger json */ private String getSwaggerJsonString(Swagger swaggerObj) throws APIManagementException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(SerializationFeature.INDENT_OUTPUT); //this is to ignore "originalRef" in schema objects mapper.addMixIn(RefModel.class, IgnoreOriginalRefMixin.class); mapper.addMixIn(RefProperty.class, IgnoreOriginalRefMixin.class); mapper.addMixIn(RefPath.class, IgnoreOriginalRefMixin.class); mapper.addMixIn(RefParameter.class, IgnoreOriginalRefMixin.class); mapper.addMixIn(RefResponse.class, IgnoreOriginalRefMixin.class); //this is to ignore "responseSchema" in response schema objects mapper.addMixIn(Response.class, ResponseSchemaMixin.class); try { return new String(mapper.writeValueAsBytes(swaggerObj)); } catch (JsonProcessingException e) { throw new APIManagementException("Error while generating Swagger json from model", e); } }
From source file:storage.FileStorageInterface.java
private static ObjectMapper initMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.enable(SerializationFeature.CLOSE_CLOSEABLE); mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); return mapper; }