etugarev commented on a change in pull request #17: SLING-8706 - Injections for
java.util.Optional<> should be automatically optional
URL:
https://github.com/apache/sling-org-apache-sling-models-impl/pull/17#discussion_r347152799
##########
File path:
src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java
##########
@@ -98,6 +99,11 @@ public Object getValue(@NotNull Object adaptable, String
name, @NotNull Type typ
return null;
}
Class<?> collectionType = (Class<?>) pType.getRawType();
+
+ if (collectionType.equals(Optional.class)) {
+ return Optional.ofNullable(map.get(name));
Review comment:
I like the idea to make it work with other injectors too, so I'll give it a
shot. Thanks for pointing out the second use case, somehow i missed that. Will
get back with a better code!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services