[ 
https://issues.apache.org/jira/browse/LANG-790?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13223818#comment-13223818
 ] 

Gokul Nanthakumar C commented on LANG-790:
------------------------------------------

Thanks for your Comment Gary, Below is what I am thinking about it

IMO, the request is not for another expression language or interpreter, it is 
for just an utility method for easy navigation.

you can see lot of codes like 

if(a!=null && a.getB()!=null && a.getB().getC())

in so many places, so basically we have some navigation issue with Null, having 
a reusable Util method to this problem is what I am looking for.

Simple solution I can propose here is using Reflect navigate through the 
object, if any Null encountered in the requested path, just return the default 
value.

JXPath - I already listed the reasons why JXPath is not ideal for this issue 
IMO.

JavaScript in Java6 - I guess this is not a solution for the problem we are 
trying to solve in Java, converting Java Object to java script object each time 
may not be a good choice, if this is the choice even we can use groovy or any 
other languages supported by JVM to solve this problem, the main objective is 
to find easy solution with in java not outside.

You say "as soon you invent a language today, you'll need more tomorrow" , yes 
true that is the nature and I dont see any mistake with this, this how a 
language or anything can evolve and mature, if we are not looking for more 
there will not be any growth in anything.

for your question on Arrays, Collections, Maps --> when we can navigate an 
object safely on nulls, we can do so in these as well, after all they are all 
just group of Objects.

for your question on Private Methods --> I am not sure what is your point with 
Private methods.

for your point on Full Interpreter --> I am not sure what is the need of 
interpreter in this case.

Please share your view, thanks.
                
> Null safe Navigation in ObjectUtils
> -----------------------------------
>
>                 Key: LANG-790
>                 URL: https://issues.apache.org/jira/browse/LANG-790
>             Project: Commons Lang
>          Issue Type: New Feature
>            Reporter: Gokul Nanthakumar C
>
> Adding a method for null safe navigation of objects will be very helpful. for 
> example a method like
> ObjectUtils.getValue(Object obj, String "path", String defaultValue); 
> ex :ObjectUtils.getValue(myObject, "x.y.z", "default");
> it will navigate in the myObject like myObject.getX().getY().getZ(), if any 
> thing in the path is null (x,y or z), it will return the default value.
> It will be really useful, it is like null safe navigation in groovy.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to