Skip to content

Commit

Permalink
Merge remote-tracking branch 'Tim203/feature/interfaces'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Jun 12, 2024
2 parents 2d8e6c8 + 4347700 commit 293c01c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.spongepowered.configurate.ConfigurationOptions;
import org.spongepowered.configurate.serialize.TypeSerializerCollection;

import java.util.function.UnaryOperator;

/**
* This class has the default {@link ConfigurationOptions}
* with {@link InterfaceTypeSerializer} added to the serializers.
Expand All @@ -29,15 +27,12 @@
*/
public final class InterfaceDefaultOptions {

private static final ConfigurationOptions DEFAULTS =
ConfigurationOptions.defaults()
.serializers(
private static final TypeSerializerCollection DEFAULTS =
TypeSerializerCollection.builder()
.registerAnnotated(InterfaceTypeSerializer::applicable, InterfaceTypeSerializer.INSTANCE)
.registerAnnotatedObjects(InterfaceMiddleware.buildObjectMapperWithMiddleware())
.registerAll(TypeSerializerCollection.defaults())
.build()
);
.build();

private InterfaceDefaultOptions() {
}
Expand All @@ -48,21 +43,21 @@ private InterfaceDefaultOptions() {
* @return the default ConfigurationOptions with {@link InterfaceTypeSerializer} added to the serializers.
* @since 4.2.0
*/
public static ConfigurationOptions get() {
return DEFAULTS;
public static ConfigurationOptions defaults() {
return addTo(ConfigurationOptions.defaults());
}

/**
* Sets the default configuration options to be used by the resultant loader
* by providing a function which takes the current {@link #get() default options}
* and applies any desired changes.
* by providing a function which takes interface's default serializer
* collection and applies any desired changes.
*
* @param options to transform the existing default options
* @return the default options with the applied changes
* @since 4.2.0
*/
public static ConfigurationOptions with(final UnaryOperator<ConfigurationOptions> options) {
return options.apply(DEFAULTS);
public static ConfigurationOptions addTo(final ConfigurationOptions options) {
return options.serializers(DEFAULTS.childBuilder().registerAll(options.serializers()).build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InterfaceTypeSerializerTest {

@Test
void testDeserialization() throws ConfigurateException {
final BasicConfigurationNode node = BasicConfigurationNode.root(InterfaceDefaultOptions.get());
final BasicConfigurationNode node = BasicConfigurationNode.root(InterfaceDefaultOptions.defaults());
// doesn't deserialize if value is NullValue
node.node("hello").set("world");

Expand All @@ -41,7 +41,7 @@ void testDeserialization() throws ConfigurateException {

@Test
void testInnerDeserialization() throws ConfigurateException {
final BasicConfigurationNode node = BasicConfigurationNode.root(InterfaceDefaultOptions.get());
final BasicConfigurationNode node = BasicConfigurationNode.root(InterfaceDefaultOptions.defaults());
// doesn't deserialize if value is NullValue
node.node("hello").set("world");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ static <T> Class<? extends T> configImplementationFor(final Class<T> interfaceCl
}
}

@SuppressWarnings("UnstableApiUsage")
private static <T> String implClassNameFor(final Class<T> interfaceClass) {
final String packageName = interfaceClass.getPackage().getName();
// include the package name dot as well
Expand Down

0 comments on commit 293c01c

Please sign in to comment.