-
Notifications
You must be signed in to change notification settings - Fork 41
3rd party class customization #279
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
Open
Verdent
wants to merge
12
commits into
jakartaee:master
Choose a base branch
from
Verdent:3rd-party-class-customization
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0a6ffdb
3rd party class customization
Verdent 9c6782a
3rd party class customization
Verdent 4a072f2
DecoratorBuilderProvider removed
Verdent 88a18e7
JsonbProvider SPI searching reworked
Verdent a4d3c51
instance changed to volatile
Verdent 52ef94a
Javadoc wording updated
Verdent fb62caa
Name refactored to customization
Verdent 3733600
Jan's suggestions implemented
Verdent 351b92e
Daniels suggestions implemented
Verdent eda10e1
Both scope removed
Verdent 0950a50
Ignored annotation option added, nillable method wording changed
Verdent bcf0ad4
Naming changed to the get format and remaining ignore methods added
Verdent 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
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
api/src/main/java/jakarta/json/bind/decorator/BuilderProviderLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2021 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 | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package jakarta.json.bind.decorator; | ||
|
||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
import java.util.ServiceLoader; | ||
|
||
import jakarta.json.bind.spi.DecoratorBuilderProvider; | ||
|
||
/** | ||
* SPI loader of the {@link DecoratorBuilderProvider}. | ||
*/ | ||
class BuilderProviderLoader { | ||
|
||
private static DecoratorBuilderProvider instance = null; | ||
|
||
private BuilderProviderLoader() { | ||
throw new IllegalStateException("This class cannot be instantiated"); | ||
} | ||
|
||
static DecoratorBuilderProvider provider() { | ||
if (instance == null) { | ||
synchronized (DecoratorBuilderProvider.class) { | ||
if (instance != null) { | ||
return instance; | ||
} | ||
PrivilegedAction<DecoratorBuilderProvider> loader = () -> | ||
Verdent marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ServiceLoader.load(DecoratorBuilderProvider.class) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalStateException("Could not find any BuilderProvider implementation")); | ||
instance = AccessController.doPrivileged(loader); | ||
} | ||
} | ||
return instance; | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
api/src/main/java/jakarta/json/bind/decorator/CommonDecorator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2021 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 | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package jakarta.json.bind.decorator; | ||
|
||
import java.text.DateFormat; | ||
import java.text.NumberFormat; | ||
import java.util.Optional; | ||
|
||
import jakarta.json.bind.adapter.JsonbAdapter; | ||
import jakarta.json.bind.serializer.JsonbDeserializer; | ||
|
||
/** | ||
* Common interface for all of the decorators. | ||
*/ | ||
public interface CommonDecorator { | ||
Verdent marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Return {@link NumberFormat} specified to the required {@link Scope}. | ||
* | ||
* @param scope required scope | ||
* @return specified {@link NumberFormat} instance, otherwise empty | ||
*/ | ||
Optional<NumberFormat> numberFormat(Scope scope); | ||
|
||
/** | ||
* Return {@link DateFormat} specified to the required {@link Scope}. | ||
* | ||
* @param scope required scope | ||
* @return specified {@link DateFormat} instance, otherwise empty | ||
*/ | ||
Optional<DateFormat> dateFormat(Scope scope); | ||
|
||
/** | ||
* Return {@link JsonbDeserializer} of the component. | ||
* | ||
* @return component deserializer instance, otherwise empty | ||
*/ | ||
Optional<JsonbDeserializer<?>> deserializer(); | ||
|
||
/** | ||
* Return {@link JsonbAdapter} of the component. | ||
* | ||
* @return component adapter instance, otherwise empty | ||
*/ | ||
Optional<JsonbAdapter<?, ?>> adapter(); | ||
|
||
/** | ||
* Return if the component can be nillable in the given {@link Scope}. | ||
* | ||
* @param scope required scope | ||
* @return property nillable state, otherwise empty | ||
*/ | ||
Optional<Boolean> nillable(Scope scope); | ||
|
||
} |
128 changes: 128 additions & 0 deletions
128
api/src/main/java/jakarta/json/bind/decorator/CommonDecoratorBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* Copyright (c) 2021 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 | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package jakarta.json.bind.decorator; | ||
|
||
import java.text.DateFormat; | ||
import java.text.NumberFormat; | ||
import java.util.Locale; | ||
|
||
import jakarta.json.bind.adapter.JsonbAdapter; | ||
import jakarta.json.bind.serializer.JsonbDeserializer; | ||
|
||
/** | ||
* Common interface for all decorator builders. | ||
*/ | ||
public interface CommonDecoratorBuilder<T extends CommonDecoratorBuilder<T, B>, B> { | ||
|
||
/** | ||
* Whether this component can be nillable. | ||
* | ||
* @param nillable nillable component | ||
* @return updated builder instance | ||
*/ | ||
T nillable(boolean nillable); | ||
|
||
/** | ||
* Set {@link JsonbDeserializer} which should be used. | ||
* | ||
* @param deserializer component deserializer | ||
* @return updated builder instance | ||
*/ | ||
T deserializer(JsonbDeserializer<?> deserializer); | ||
|
||
/** | ||
* Set {@link JsonbAdapter} which should be used. | ||
* | ||
* @param adapter component adapter | ||
* @return updated builder instance | ||
*/ | ||
T adapter(JsonbAdapter<?, ?> adapter); | ||
|
||
/** | ||
* Set number format and locale which should be used. | ||
* | ||
* @param numberFormat number format | ||
* @param locale locale | ||
* @return updated builder instance | ||
*/ | ||
T numberFormat(String numberFormat, Locale locale); | ||
|
||
/** | ||
* Set number format which should be used. | ||
* | ||
* @param numberFormat number format | ||
* @return updated builder instance | ||
*/ | ||
T numberFormat(String numberFormat); | ||
|
||
/** | ||
* Set locale which should be used. | ||
* | ||
* @param locale locale | ||
* @return updated builder instance | ||
*/ | ||
T numberFormat(Locale locale); | ||
|
||
/** | ||
* Set {@link NumberFormat} instance which should be used. | ||
* | ||
* @param numberFormat pre created NumberFormat instance | ||
* @return updated builder instance | ||
*/ | ||
T numberFormat(NumberFormat numberFormat); | ||
|
||
/** | ||
* Set date format and locale which should be used. | ||
* | ||
* @param dateFormat date format | ||
* @param locale locale | ||
* @return updated builder instance | ||
*/ | ||
T dateFormat(String dateFormat, Locale locale); | ||
|
||
/** | ||
* Set date format which should be used. | ||
* | ||
* @param dateFormat date format | ||
* @return updated builder instance | ||
*/ | ||
T dateFormat(String dateFormat); | ||
|
||
/** | ||
* Set locale which should be used. | ||
* | ||
* @param locale locale | ||
* @return updated builder instance | ||
*/ | ||
T dateFormat(Locale locale); | ||
|
||
/** | ||
* Set {@link DateFormat} instance which should be used. | ||
* | ||
* @param dateFormat pre created DateFormat instance | ||
* @return updated builder instance | ||
*/ | ||
T dateFormat(DateFormat dateFormat); | ||
|
||
/** | ||
* Build the new instance from this builder. | ||
* | ||
* @return new instance | ||
*/ | ||
B build(); | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
api/src/main/java/jakarta/json/bind/decorator/CreatorDecorator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2021 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 | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package jakarta.json.bind.decorator; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Decorated creator customization. | ||
*/ | ||
public interface CreatorDecorator { | ||
|
||
/** | ||
* Create new {@link CreatorDecoratorBuilder} instance. | ||
* | ||
* Builder created via this method targets constructors of the class it is bound to. | ||
* | ||
* @return new creator decorator builder instance | ||
*/ | ||
static CreatorDecoratorBuilder builder() { | ||
return BuilderProviderLoader.provider().newCreatorDecoratorBuilder(); | ||
} | ||
|
||
/** | ||
* Create new {@link CreatorDecoratorBuilder} instance based on creator method name. | ||
* | ||
* @return new creator decorator builder instance | ||
*/ | ||
static CreatorDecoratorBuilder builder(String methodName) { | ||
return BuilderProviderLoader.provider().newCreatorDecoratorBuilder(methodName); | ||
} | ||
|
||
/** | ||
* Return creator method name if has been specified. | ||
* If the name is empty, it is handled as if it is null. | ||
* | ||
* @return specified creator method name, otherwise empty | ||
*/ | ||
Optional<String> factoryMethodName(); | ||
|
||
/** | ||
* Return {@link List} of the registered parameters. The order of the parameters needs to be the same as they were added. | ||
Verdent marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* If no parameters were added, empty {@link List} is returned. | ||
* | ||
* @return creator parameters | ||
*/ | ||
List<ParamDecorator> params(); | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we drop the two entry points from this class we can make this whole PR an appendix - same as proposing the introspector/annotation based solution - of the spec while there is not agreement on the final outcome.
Can enable to have API proposals and decide later (bean validation went that way in its time - for method validation).
Overall blocking point is to have something unified versus something duplicated for 3rd party libraries and I don't see us choosing before next release since both parties seems to either priviledge the interoperability and simplicity or the application API first (being said the introspector API enables to join the API point later if needed whereas decorator does not and keeps two concurrent models in the spec forever).
Wdyt? (trying to not block but not pollute the API too early without enabling 3rd party cases)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly do you mean by "drop the two entry points from this class". I am sorry, but I don't understand what you are trying to say. Please explain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not make it explicit in the API (ie use yasson.decorators property without a constant nor a wither.