From 7a85bdd4a1d80778013819e1401adde561af58da Mon Sep 17 00:00:00 2001 From: "igor.petrenko" Date: Tue, 29 Aug 2023 07:41:14 +0300 Subject: [PATCH] add: Binder#Format#of(String) --- oap-stdlib/src/main/java/oap/json/Binder.java | 8 +++++++- oap-stdlib/src/main/java/oap/reflect/Coercions.java | 8 ++++---- pom.xml | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/oap-stdlib/src/main/java/oap/json/Binder.java b/oap-stdlib/src/main/java/oap/json/Binder.java index fd0196fc61..8faa1d8575 100644 --- a/oap-stdlib/src/main/java/oap/json/Binder.java +++ b/oap-stdlib/src/main/java/oap/json/Binder.java @@ -68,6 +68,7 @@ import oap.reflect.TypeRef; import oap.util.Dates; import oap.util.function.Try; +import org.jetbrains.annotations.NotNull; import org.joda.time.ReadableInstant; import java.io.IOException; @@ -639,12 +640,17 @@ public enum Format { this.binder = binder; } + @NotNull public static Format of( URL url, boolean withSystemProperties ) { var path = url.toString().toLowerCase(); + return of( path, withSystemProperties ); + } + + @NotNull + public static Format of( String path, boolean withSystemProperties ) { if( path.endsWith( "json" ) ) return JSON; else if( path.endsWith( "yaml" ) || path.endsWith( "yml" ) ) return YAML; return withSystemProperties ? HOCON : HOCON_WO_SYSTEM_PROPERTIES; } } - } diff --git a/oap-stdlib/src/main/java/oap/reflect/Coercions.java b/oap-stdlib/src/main/java/oap/reflect/Coercions.java index 50b1bd8285..df99a69f66 100644 --- a/oap-stdlib/src/main/java/oap/reflect/Coercions.java +++ b/oap-stdlib/src/main/java/oap/reflect/Coercions.java @@ -69,13 +69,13 @@ public final class Coercions { static { functions.put( "path", Try.biMap( ( path, reflection ) -> - Binder.hoconWithoutSystemProperties.unmarshal( reflection, Path.of( path ) ) ) ); + Binder.Format.of( path, false ).binder.unmarshal( reflection, Path.of( path ) ) ) ); functions.put( "file", Try.biMap( ( path, reflection ) -> - Binder.hoconWithoutSystemProperties.unmarshal( reflection, Path.of( path ) ) ) ); + Binder.Format.of( path, false ).binder.unmarshal( reflection, Path.of( path ) ) ) ); functions.put( "url", Try.biMap( ( url, reflection ) -> - Binder.hoconWithoutSystemProperties.unmarshal( reflection, new URL( url ) ) ) ); + Binder.Format.of( url, false ).binder.unmarshal( reflection, new URL( url ) ) ) ); functions.put( "classpath", Try.biMap( ( cp, reflection ) -> - Binder.hoconWithoutSystemProperties.unmarshal( reflection, Coercions.class.getResource( cp ) ) ) ); + Binder.Format.of( cp, false ).binder.unmarshal( reflection, Coercions.class.getResource( cp ) ) ) ); functions.put( "str", Try.biMap( ( str, reflection ) -> Binder.hoconWithoutSystemProperties.unmarshal( reflection, str ) ) ); functions.put( "hocon", Try.biMap( ( str, reflection ) -> diff --git a/pom.xml b/pom.xml index bafa8dbff4..a4da44eb45 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ - 18.11.5.28 + 18.11.5.29 7.8.0 3.24.2