Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for multiple JSON providers #383

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Solve conflicts
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
  • Loading branch information
jbescos committed Feb 23, 2024
commit 7c53efb65f2cd409ec63b809b2af0c7f97f10d65
20 changes: 14 additions & 6 deletions api/src/main/java/jakarta/json/spi/JsonProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -105,12 +105,11 @@ protected JsonProvider() {
*
* @see ServiceLoader
* @return a JSON provider
*
*/
public static JsonProvider provider() {
return provider(null);
}

/**
* Creates a JSON provider object.
*
Expand All @@ -133,11 +132,18 @@ public static JsonProvider provider() {
* @param providerClassName The name of the class to be found from the {@link ServiceLoader#load(Class)}.
* @return a JSON provider
*
* @since 2.1.1
* @since 2.2.0
*/
public static JsonProvider provider(String providerClassName) {
if (LazyFactoryLoader.JSON_PROVIDER != null) {
return newInstance(LazyFactoryLoader.JSON_PROVIDER);
LOG.log(Level.FINE, "Checking system property {0}", JSONP_PROVIDER_FACTORY);
final String factoryClassName = System.getSecurityManager() != null
? AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(JSONP_PROVIDER_FACTORY))
: System.getProperty(JSONP_PROVIDER_FACTORY);
if (factoryClassName != null) {
JsonProvider provider = newInstance(factoryClassName);
LOG.log(Level.FINE, "System property used; returning object [{0}]",
provider.getClass().getName());
return provider;
}

LOG.log(Level.FINE, "Checking ServiceLoader");
Expand All @@ -146,6 +152,8 @@ public static JsonProvider provider(String providerClassName) {
while (it.hasNext()) {
JsonProvider provider = it.next();
if (providerClassName == null || provider.getClass().getName().equals(providerClassName)) {
LOG.log(Level.FINE, "ServiceLoader loading Facility used; returning object [{0}]",
provider.getClass().getName());
return provider;
}
}
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.