Skip to content

Commit

Permalink
add: Binder#Format#of(String)
Browse files Browse the repository at this point in the history
  • Loading branch information
nofateg authored Aug 29, 2023
1 parent caa06c5 commit 7a85bdd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 7 additions & 1 deletion oap-stdlib/src/main/java/oap/json/Binder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

}
8 changes: 4 additions & 4 deletions oap-stdlib/src/main/java/oap/reflect/Coercions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ->
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</repositories>

<properties>
<oap.project.version>18.11.5.28</oap.project.version>
<oap.project.version>18.11.5.29</oap.project.version>

<oap.deps.testng.version>7.8.0</oap.deps.testng.version>
<oap.deps.assertj.version>3.24.2</oap.deps.assertj.version>
Expand Down

0 comments on commit 7a85bdd

Please sign in to comment.