-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14792 from geoand/rr-optional-params
Add Optional parameter support in RESTEasy Reactive
- Loading branch information
Showing
11 changed files
with
122 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
63 changes: 63 additions & 0 deletions
63
...java/org/jboss/resteasy/reactive/server/core/parameters/converters/OptionalConverter.java
This file contains 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 @@ | ||
package org.jboss.resteasy.reactive.server.core.parameters.converters; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
import java.util.Optional; | ||
import org.jboss.resteasy.reactive.server.model.ParamConverterProviders; | ||
|
||
public class OptionalConverter implements ParameterConverter { | ||
|
||
private final ParameterConverter delegate; | ||
|
||
public OptionalConverter(ParameterConverter delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public Object convert(Object parameter) { | ||
if (parameter == null) { | ||
return Optional.empty(); | ||
} else if (delegate != null) { | ||
return Optional.ofNullable(delegate.convert(parameter)); | ||
} else { | ||
return Optional.of(parameter); | ||
} | ||
} | ||
|
||
@Override | ||
public void init(ParamConverterProviders deployment, Class<?> rawType, Type genericType, Annotation[] annotations) { | ||
delegate.init(deployment, rawType, genericType, annotations); | ||
} | ||
|
||
public static class OptionalSupplier implements DelegatingParameterConverterSupplier { | ||
private ParameterConverterSupplier delegate; | ||
|
||
public OptionalSupplier() { | ||
} | ||
|
||
public OptionalSupplier(ParameterConverterSupplier delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public ParameterConverter get() { | ||
return delegate == null ? new OptionalConverter(null) : new OptionalConverter(delegate.get()); | ||
} | ||
|
||
public ParameterConverterSupplier getDelegate() { | ||
return delegate; | ||
} | ||
|
||
public OptionalSupplier setDelegate(ParameterConverterSupplier delegate) { | ||
this.delegate = delegate; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getClassName() { | ||
return OptionalConverter.class.getName(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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