Refine search
private Schema parseDependencies(CTLSchemaDto schema, final Schema.Parser parser) throws Exception { if (schema.getDependencySet() != null) { for (CTLSchemaDto dependency : schema.getDependencySet()) { this.parseDependencies(dependency, parser); } } ObjectNode object = new ObjectMapper().readValue(schema.getBody(), ObjectNode.class); object.remove(DEPENDENCIES); String body = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(object); return parser.parse(body); }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { // admin check - // allows when hadoop.security.instrumentation.requires.admin is set to false // when hadoop.security.instrumentation.requires.admin is set to true, checks if hadoop.security.authorization // is true and if the logged in user (via PAM or SPNEGO + kerberos) is in hive.users.in.admin.role list final ServletContext context = getServletContext(); if (!HttpServer.isInstrumentationAccessAllowed(context, request, response)) { LOG.warn("Unauthorized to perform GET action. remoteUser: {}", request.getRemoteUser()); return; } setResponseHeaders(response); ServletContext ctx = getServletContext(); AtomicBoolean isLeader = (AtomicBoolean) ctx.getAttribute("hs2.isLeader"); LOG.info("Returning isLeader: {}", isLeader); ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(response.getWriter(), isLeader); response.setStatus(HttpServletResponse.SC_OK); response.flushBuffer(); }
public static String prettyPrint( Object item ) throws IOException { return OBJECT_MAPPER.writer().withDefaultPrettyPrinter().writeValueAsString( item ); } }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String endpointKey = URLDecoder.decode(request.getParameter(ENDPOINT_KEY_PARAMETER), "UTF-8"); try { String json = configurationService.findEndpointConfigurationByEndpointKeyHash(endpointKey); String fileName = MessageFormatter.arrayFormat(EP_CONF_FILE_NAME_PATTERN, new Object[]{endpointKey}).getMessage(); Object jsonObject = FORMATTER.readValue(json, Object.class); byte[] body = FORMATTER.writerWithDefaultPrettyPrinter() .writeValueAsString(jsonObject) .getBytes("UTF-8"); ServletUtils.prepareDisposition(request, response, fileName); response.setContentType(JSON); response.setContentLength(body.length); response.setBufferSize(BUFFER); response.getOutputStream().write(body); response.flushBuffer(); } catch (Exception ex) { LOG.error("Unexpected error in ProfileDownloadServlet.doGet: ", ex); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to get file: " + ex.getMessage()); } } }
public static String toJSON(final Object obj, final boolean prettyPrint) { final ObjectMapper mapper = new ObjectMapper(); try { if (prettyPrint) { final ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter(); return writer.writeValueAsString(obj); } return mapper.writeValueAsString(obj); } catch (final Exception e) { throw new RuntimeException(e); } }
public static void toJSON(final Object obj, final OutputStream stream, final boolean prettyPrint) { final ObjectMapper mapper = new ObjectMapper(); try { if (prettyPrint) { final ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter(); writer.writeValue(stream, obj); return; } mapper.writeValue(stream, obj); } catch (final Exception e) { throw new RuntimeException(e); } }
/** * Convert a SearchRequest to JSON. * @param request The search request. * @return The JSON representation of the SearchRequest. */ public static Optional<String> toJSON(Object request) { Optional<String> json = Optional.empty(); if(request != null) { try { json = Optional.of( new ObjectMapper() .writer() .withDefaultPrettyPrinter() .writeValueAsString(request)); } catch (Throwable t) { LOG.error("Failed to convert request to JSON", t); } } return json; }
public void outputJson(PrintWriter writer) throws LlapStatusCliException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_EMPTY); mapper.setVisibility(JsonMethod.ALL, Visibility.NON_PRIVATE); try { writer.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(appStatusBuilder)); } catch (IOException e) { LOG.warn("Failed to create JSON", e); throw new LlapStatusCliException(ExitCode.LLAP_JSON_GENERATION_ERROR, "Failed to create JSON", e); } }
private static String jacksonPrettyPrint( final String json ) throws Exception { Object myObject = MAPPER.readValue( json, Object.class ); return WRITER.writeValueAsString( myObject ); } }
@JsonIgnore public String toJson() throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this); } }
public void printJson(final SessionState.LogHelper console) { try { waitForReturnSessionEvent(); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); // serialize json based on field annotations only objectMapper.setVisibilityChecker(objectMapper.getSerializationConfig().getDefaultVisibilityChecker() .withSetterVisibility(JsonAutoDetect.Visibility.NONE)); String wmContextJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(this); console.printInfo(""); console.printInfo(WM_EVENTS_TITLE); console.printInfo(SEPARATOR); console.printInfo(wmContextJson); console.printInfo(SEPARATOR); console.printInfo(""); } catch (Exception e) { LOG.warn("Unable to serialize WMContext to json.", e); } }
@Override public void writeTo(ServiceNames serviceNames, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { ObjectMapper mapper = new ObjectMapper(); ArrayNode arrayNode = mapper.createArrayNode(); for ( String name : serviceNames.getNames() ) { ObjectNode node = mapper.createObjectNode(); node.put("name", name); arrayNode.add(node); } mapper.writer().writeValue(entityStream, arrayNode); }
/** * Utility function good for testing things. Prints out the json tree of the * JmxProcess. */ public static void prettyPrintJson(JmxProcess process) throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.getSerializationConfig().set(Feature.WRITE_NULL_MAP_VALUES, false); ObjectWriter writer = mapper.defaultPrettyPrintingWriter(); System.out.println(writer.writeValueAsString(process)); }
public static void writePrettyPrint(Writer w, Object jsonObject) throws JsonGenerationException, JsonMappingException, IOException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.getJsonFactory().disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); ObjectWriter objectWriter = objectMapper.writerWithDefaultPrettyPrinter(); objectWriter.writeValue(w, jsonObject); }
/** * Generate bson from java object. * * @param obj * the obj * @return the BSON object */ protected BSONObject generateBSONFromJavaObject(Object obj) { ObjectWriter ow = new ObjectMapper().writer(); String json = null; try { json = ow.writeValueAsString(obj); return (BSONObject) JSON.parse(json); } catch (JsonGenerationException | JsonMappingException e) { throw new KunderaException( "Error in converting BSON Object from Java Object due to error in JSON generation/mapping. Caused BY:", e); } catch (IOException e) { throw new KunderaException("Error in converting BSON Object from Java Object. Caused BY:", e); } }
@Override public void writeTo(ServiceInstance<T> serviceInstance, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { ObjectMapper mapper = new ObjectMapper(); ObjectNode node = writeInstance(mapper, serviceInstance, context); mapper.writer().writeValue(entityStream, node); } }
private static String toJSON(ParquetMetadata parquetMetaData, boolean isPrettyPrint) { StringWriter stringWriter = new StringWriter(); try { if (isPrettyPrint) { objectMapper.writerWithDefaultPrettyPrinter().writeValue(stringWriter, parquetMetaData); } else { objectMapper.writeValue(stringWriter, parquetMetaData); } } catch (JsonGenerationException e) { throw new RuntimeException(e); } catch (JsonMappingException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } return stringWriter.toString(); }
@Override public void serialize(OutputStream out, T object, TypeDef<?> type) throws IOException { if (type == null) { mapper.writeValue(out, object); } else { ObjectWriter writer = mapper.writerWithType(new TypeTokenBasedReference(type)); writer.writeValue(out, object); } }
public static String nodeToJsonPretty(JsonNode a) { try { return Tools.MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(a); } catch (IOException e) { e.printStackTrace(); } return null; }
@Override public String toString() { try { return WRITER.writeValueAsString(innerMetrics); } catch (IOException e) { LOG.warn("Failed to dump to Json.", e); return ExceptionUtils.getStackTrace(e); } } }