@Override public JavaPropsMapper build() { return new JavaPropsMapper(this); }
@Override public JavaPropsMapper copy() { _checkInvalidCopy(JavaPropsMapper.class); return new JavaPropsMapper(this); }
/** * Convenience method, functionally equivalent to: *<pre> * readPropertiesAs(convertMapToProperties(System.getenv()), schema, valueType); *</pre> * * @since 2.9 */ public <T> T readEnvVariablesAs(JavaPropsSchema schema, Class<T> valueType) throws IOException { return readPropertiesAs(_env(), schema, valueType); }
private Map<String, String> readConfigFromJavaPropertiesType(InputStream configFileStream) throws IOException { ObjectReader reader = new JavaPropsMapper().reader(JavaPropsSchema.emptySchema().withoutPathSeparator()); return reader.forType(new TypeReference<Map<String, Object>>() {}).readValue(configFileStream); }
/** * Convenience method which uses given `Properties` as the source * as if they had been read from an external source, processes * them (splits paths etc), and then binds as given result * value. *<p> * Note that this is NOT identical to calling {@link #convertValue(Object, Class)}; * rather, it would be similar to writing `Properties` out into a File, * then calling `readValue()` on this mapper to bind contents. */ @SuppressWarnings({ "resource", "unchecked" }) public <T> T readPropertiesAs(Properties props, JavaPropsSchema schema, JavaType valueType) throws IOException { DeserializationContext ctxt = createDeserializationContext(); JsonParser p = tokenStreamFactory().createParser(ctxt, props); p.setSchema(schema); return (T) readValue(p, valueType); }
/** * Convenience method that "writes" given `value` as properties * in given {@link Properties} object. */ public void writeValue(Properties targetProps, Object value) throws IOException { if (targetProps == null) { throw new IllegalArgumentException("Can not pass null Properties as target"); } DefaultSerializerProvider prov = _serializerProvider(); JavaPropsGenerator g = tokenStreamFactory() .createGenerator(prov, targetProps); writeValue(g, value); g.close(); }
/** * Convenience method which uses given `Properties` as the source * as if they had been read from an external source, processes * them (splits paths etc), and then binds as given result * value. *<p> * Note that this is NOT identical to calling {@link #convertValue(Object, Class)}; * rather, it would be similar to writing `Properties` out into a File, * then calling `readValue()` on this mapper to bind contents. * * @since 2.9 */ @SuppressWarnings("resource") public <T> T readPropertiesAs(Properties props, JavaPropsSchema schema, Class<T> valueType) throws IOException { JsonParser p = getFactory().createParser(props); p.setSchema(schema); return (T) readValue(p, valueType); }
/** * 反序列化Recources目录下的Properties文件 * @param name 文件名 */ public static <V> V fromPropRecource(String name, Class<V> c) { try (InputStream inputStream = getResourceStream(name); InputStreamReader reader = getResourceReader(inputStream)) { if (reader == null) { return null; } return propsMapper.readValue(reader, c); } catch (IOException e) { log.error("jackson from properties recource error, name: {}, type: {}", name, c, e); return null; } }
private static void configIndentOutput() { mapper.configure(SerializationFeature.INDENT_OUTPUT, IS_ENABLE_INDENT_OUTPUT); yamlMapper.configure(SerializationFeature.INDENT_OUTPUT, IS_ENABLE_INDENT_OUTPUT); propsMapper.configure(SerializationFeature.INDENT_OUTPUT, IS_ENABLE_INDENT_OUTPUT); csvMapper.configure(SerializationFeature.INDENT_OUTPUT, IS_ENABLE_INDENT_OUTPUT); xmlMapper.configure(SerializationFeature.INDENT_OUTPUT, IS_ENABLE_INDENT_OUTPUT); }
/** * Convenience method which uses given `Properties` as the source * as if they had been read from an external source, processes * them (splits paths etc), and then binds as given result * value. *<p> * Note that this is NOT identical to calling {@link #convertValue(Object, Class)}; * rather, it would be similar to writing `Properties` out into a File, * then calling `readValue()` on this mapper to bind contents. */ @SuppressWarnings("resource") public <T> T readPropertiesAs(Properties props, JavaPropsSchema schema, Class<T> valueType) throws IOException { DeserializationContext ctxt = createDeserializationContext(); JsonParser p = tokenStreamFactory().createParser(ctxt, props); p.setSchema(schema); return (T) readValue(p, valueType); }
/** * Convenience method that "writes" given `value` as properties * in given {@link Properties} object. */ public void writeValue(Properties targetProps, Object value, JavaPropsSchema schema) throws IOException { if (targetProps == null) { throw new IllegalArgumentException("Can not pass null Properties as target"); } DefaultSerializerProvider prov = _serializerProvider(); JavaPropsGenerator g = tokenStreamFactory() .createGenerator(prov, targetProps); if (schema != null) { g.setSchema(schema); } writeValue(g, value); g.close(); }
/** * Convenience method which uses given `Properties` as the source * as if they had been read from an external source, processes * them (splits paths etc), and then binds as given result * value. *<p> * Note that this is NOT identical to calling {@link #convertValue(Object, Class)}; * rather, it would be similar to writing `Properties` out into a File, * then calling `readValue()` on this mapper to bind contents. * * @since 2.9 */ @SuppressWarnings({ "resource", "unchecked" }) public <T> T readPropertiesAs(Properties props, JavaPropsSchema schema, JavaType valueType) throws IOException { JsonParser p = getFactory().createParser(props); p.setSchema(schema); return (T) readValue(p, valueType); }
/** * 反序列化Recources目录下的Properties文件 * @param name 文件名 */ public static <V> V fromPropRecource(String name, TypeReference<V> type) { try (InputStream inputStream = getResourceStream(name); InputStreamReader reader = getResourceReader(inputStream)) { if (reader == null) { return null; } return propsMapper.readValue(reader, type); } catch (IOException e) { log.error("jackson from properties recource error, name: {}, type: {}", name, type, e); return null; } }
private void writeConfigToPropertiesTypeFile(Map<String, String> configuration, File destPath) throws IOException { ObjectMapper objectMapper = new JavaPropsMapper(); objectMapper.writeValue(destPath, configuration); }
/** * Convenience method, functionally equivalent to: *<pre> * readPropertiesAs(convertMapToProperties(System.getenv()), schema, valueType); *</pre> * * @since 2.9 */ public <T> T readEnvVariablesAs(JavaPropsSchema schema, JavaType valueType) throws IOException { return readPropertiesAs(_env(), schema, valueType); }
public PropertiesSerializer(TopicDataType<T> topicDataType) { super(topicDataType, new JavaPropsMapper()); setAddTypeAsRootNode(false); } }
/** * Convenience method, functionally equivalent to: *<pre> * readPropertiesAs(convertMapToProperties(System.getenv()), schema, valueType); *</pre> */ public <T> T readEnvVariablesAs(JavaPropsSchema schema, JavaType valueType) throws IOException { return readPropertiesAs(_env(), schema, valueType); }
public PropertiesSerializer(TopicDataType<T> topicDataType) { super(topicDataType, new JavaPropsMapper()); setAddTypeAsRootNode(false); } }
/** * Convenience method, functionally equivalent to: *<pre> * readPropertiesAs(convertMapToProperties(System.getenv()), schema, valueType); *</pre> */ public <T> T readEnvVariablesAs(JavaPropsSchema schema, Class<T> valueType) throws IOException { return readPropertiesAs(_env(), schema, valueType); }
private static void initMapper() { mapper = new ObjectMapper(); yamlMapper = new YAMLMapper(); propsMapper = new JavaPropsMapper(); csvMapper = new CsvMapper(); xmlMapper = new XmlMapper(); }