Rename getCreationContext to oneByType and make the implementation more robust

This commit is contained in:
Sebastian Sdorra
2020-09-09 14:42:07 +02:00
parent 0abe47f666
commit 01e3732c24
3 changed files with 74 additions and 9 deletions

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository;
import com.fasterxml.jackson.databind.JsonNode;
@@ -97,8 +97,12 @@ public class RepositoryInitializer {
}
@Override
public <T> Optional<T> getCreationContext(String key, Class<T> type) {
return Optional.of(mapper.convertValue(creationContext.get(key), type));
public <T> Optional<T> oneByType(String key, Class<T> type) {
JsonNode node = creationContext.get(key);
if (node != null) {
return Optional.of(mapper.convertValue(node, type));
}
return Optional.empty();
}
@Override