Skip to content

Commit

Permalink
chore: Replace abstract provider class with interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
nstdio committed Mar 27, 2022
1 parent ec0ca6d commit ce70b61
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static io.github.nstdio.http.ext.spi.Classpath.isGsonPresent;
import static io.github.nstdio.http.ext.spi.Classpath.isJacksonPresent;

class CompositeJsonMappingProvider extends JsonMappingProvider {
class CompositeJsonMappingProvider implements JsonMappingProvider {
private static final String NO_JSON_MAPPING_FOUND = "No JsonMapping implementation found. Please consider to add any of dependencies to classpath: 'com.fasterxml.jackson.core:jackson-databind', 'com.google.code.gson:gson'";

static boolean hasAnyImplementation() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2022 Edgar Asatryan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.nstdio.http.ext.spi;

final class DefaultProviderHolder {
static final CompositeJsonMappingProvider DEFAULT_PROVIDER = new CompositeJsonMappingProvider();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,13 @@
/**
* The SPI to for {@linkplain JsonMapping}.
*/
public abstract class JsonMappingProvider {

/**
* Inheritance constructor.
*/
@SuppressWarnings("WeakerAccess")
protected JsonMappingProvider() {
}

public interface JsonMappingProvider {
/**
* Finds the first available {@code JsonMappingProvider}.
*
* @return The {@code JsonMappingProvider}.
*/
public static JsonMappingProvider provider() {
static JsonMappingProvider provider() {
return loader()
.findFirst()
.or(JsonMappingProvider::defaultProvider)
Expand All @@ -51,7 +43,7 @@ public static JsonMappingProvider provider() {
*
* @throws JsonMappingProviderNotFoundException When requested provider is not found.
*/
public static JsonMappingProvider provider(String name) {
static JsonMappingProvider provider(String name) {
return loader()
.stream()
.filter(provider -> provider.type().getName().equals(name))
Expand All @@ -78,9 +70,5 @@ private static ServiceLoader<JsonMappingProvider> loader() {
*
* @return The {@code JsonMapping} instance.
*/
public abstract JsonMapping get();

private static final class DefaultProviderHolder {
private static final CompositeJsonMappingProvider DEFAULT_PROVIDER = new CompositeJsonMappingProvider();
}
JsonMapping get();
}

0 comments on commit ce70b61

Please sign in to comment.