public static void writeValue( JsonGenerator jgen, Object value ) throws IOException { OBJECT_MAPPER.writeValue( jgen, value ); }
public static void serialize(KafkaCheckpoint checkpoint, File outputFile) throws IOException { _mapper.writeValue(outputFile, checkpoint._partitionOffsetMap); }
public static void serialize(KafkaCheckpoint checkpoint, OutputStream outputStream) throws IOException { _mapper.writeValue(outputStream, checkpoint._partitionOffsetMap); }
/** * Convert a map to a json string. */ public static String mapToJson(Object obj) throws IOException { ObjectMapper mapper = new ObjectMapper(); ByteArrayOutputStream out = new ByteArrayOutputStream(); mapper.writeValue(out, obj); return out.toString(); } }
protected void writeJSON(final HttpServletResponse resp, final Object obj) throws IOException { resp.setContentType(JSON_MIME_TYPE); final ObjectMapper mapper = new ObjectMapper(); final OutputStream stream = resp.getOutputStream(); mapper.writeValue(stream, obj); }
/** * Convert the map to a JSON string. */ private void asJson(OutputStream out, Map<String, Object> data) throws HiveException { try { new ObjectMapper().writeValue(out, data); } catch (IOException e) { throw new HiveException("Unable to convert to json", e); } }
/** * Convert the map to a JSON string. */ private void asJson(OutputStream out, Map<String, Object> data) throws HiveException { try { new ObjectMapper().writeValue(out, data); } catch (IOException e) { throw new HiveException("Unable to convert to json", 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); } }
protected Object _convert(Object fromValue, JavaType toValueType) throws IllegalArgumentException { // sanity check for null first: if (fromValue == null) return null; /* Then use TokenBuffer, which is a JsonGenerator: * (see [JACKSON-175]) */ TokenBuffer buf = new TokenBuffer(this); try { writeValue(buf, fromValue); // and provide as with a JsonParser for contents as well! JsonParser jp = buf.asParser(); Object result = readValue(jp, toValueType); jp.close(); return result; } catch (IOException e) { // should not occur, no real i/o... throw new IllegalArgumentException(e.getMessage(), e); } }
JsonNode result; try { writeValue(buf, fromValue); JsonParser jp = buf.asParser(); result = readTree(jp);
ObjectMapper mapper = new ObjectMapper(); out = new ByteArrayOutputStream(); mapper.writeValue(out, statuses); return out.toString("UTF-8"); } catch (JsonGenerationException e) {
super.writeValue( out, value.toString() ); super.writeValue( out, value );
protected Object _convert(Object fromValue, JavaType toValueType) throws IllegalArgumentException { // sanity check for null first: if (fromValue == null) return null; /* Then use TokenBuffer, which is a JsonGenerator: * (see [JACKSON-175]) */ TokenBuffer buf = new TokenBuffer(this); try { writeValue(buf, fromValue); // and provide as with a JsonParser for contents as well! JsonParser jp = buf.asParser(); Object result = readValue(jp, toValueType); jp.close(); return result; } catch (IOException e) { // should not occur, no real i/o... throw new IllegalArgumentException(e.getMessage(), e); } }
/** * Generate metric data having string and boolean values using: * <li> provided timestamp * <li> random generated metric name postfix * * @param collectionTime * @return * @throws Exception */ public static String generateJSONMetricsDataWithAllWrongTypes( boolean generateRandomTenant, long collectionTime ) throws Exception { StringWriter writer = new StringWriter(); mapper.writeValue(writer, generateMetricsDataWithAllWrongTypes("", generateRandomTenant, collectionTime)); return writer.toString(); }
/** * Generate metric data having string and boolean values using: * <li> provided timestamp * <li> random generated metric name postfix * * @param collectionTime * @return * @throws Exception */ public static String generateJSONMetricsDataWithPartialWrongTypes( boolean generateRandomTenant, long collectionTime ) throws Exception { StringWriter writer = new StringWriter(); mapper.writeValue(writer, generateMetricsDataWithPartialWrongTypes("", generateRandomTenant, collectionTime)); return writer.toString(); }
/** * Generate single metric data using: * <li> provided timestamp * <li> random generated metric name postfix * * @param collectionTime * @return * @throws Exception */ private static String generateJSONMetricsData( long collectionTime ) throws Exception { StringWriter writer = new StringWriter(); mapper.writeValue(writer, generateMetricsData( "", collectionTime )); return writer.toString(); }
/** * Generate a single metric data having string value using: * <li> provided timestamp * <li> random generated metric name postfix * * @param collectionTime * @return * @throws Exception */ public static String generateJSONMetricsDataWithStringValue( long collectionTime ) throws Exception { StringWriter writer = new StringWriter(); mapper.writeValue(writer, generateMetricsDataWithStringValue("", collectionTime)); return writer.toString(); }
/** * Generate a single metric data having numeric string value using: * <li> provided timestamp * <li> random generated metric name postfix * * @param collectionTime * @return * @throws Exception */ public static String generateJSONMetricsDataWithNumericStringValue( long collectionTime ) throws Exception { StringWriter writer = new StringWriter(); mapper.writeValue(writer, generateMetricsDataWithNumericStringValue("", collectionTime)); return writer.toString(); }
/** * Generate single metric data using: * <li> provided timestamp * <li> provided metric name postfix * * @param metricPostfix * @param collectionTime * @return * @throws Exception */ public static String generateJSONMetricsData( String metricPostfix, long collectionTime ) throws Exception { StringWriter writer = new StringWriter(); mapper.writeValue(writer, generateMetricsData( metricPostfix, collectionTime )); return writer.toString(); }
/** * Write the actual JSON content to the stream. * @param stream the output stream to use * @param value the value to be rendered, as returned from {@link #filterModel} * @param jsonPrefix the prefix for this view's JSON output * (as indicated through {@link #setJsonPrefix}/{@link #setPrefixJson}) * @throws IOException if writing failed */ protected void writeContent(OutputStream stream, Object value, String jsonPrefix) throws IOException { JsonGenerator generator = this.objectMapper.getJsonFactory().createJsonGenerator(stream, this.encoding); // A workaround for JsonGenerators not applying serialization features // https://github.com/FasterXML/jackson-databind/issues/12 if (this.objectMapper.getSerializationConfig().isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) { generator.useDefaultPrettyPrinter(); } if (jsonPrefix != null) { generator.writeRaw(jsonPrefix); } this.objectMapper.writeValue(generator, value); }