/** * 反序列化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; } }
/** * 反序列化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; } }
/** * 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); }
/** * 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); }
/** * 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 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); }