-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Support for different handling of nested null properties #11
Comments
👋 Make sense! When you say "different exception", do you mean A) a different exception type or B) simply a different message? Somewhat related: note (in case you didnt know) there is a function that detects existence of a property: System.out.println(BeanUtil.declared.hasProperty(new X(), "nested.a")); // true
System.out.println(BeanUtil.declared.hasProperty(new X(), "nested.b")); // false Thank you for the feedback! |
Hi. What i'm looking for is to be able to just return null if any of the nested properties are null, but detect incorrect property names and throw exceptions. Hmm, i tested hasProperty but both returned false! X bean = new X();
System.out.println(BeanUtil.declared.hasProperty(bean, "nested.a")); // false
bean.nested = new Y(); // Nested must be inited first!
System.out.println(BeanUtil.declared.hasProperty(bean, "nested.a")); // true |
Cool, I can refine the exception types - add different subtypes, including the new one for your case. p.s. I will check the example with |
Under development, this week is just crazy :( |
It's cool, take your time! I will be happy to test it out =) |
The issue I am facing is this: in both cases, the Otherwise, we would need to validate the whole path. This validation is not guaranteed, as it might depend on runtime (for lists, maps etc). Next, the whole path could be longer, e.g. Note that the following works:
What I can do is to actually only cover the case of the immediate child:
wdyt? |
Hi. I think the behaviour in:
is good enough! |
Here it is, the test is passing... I will release a snapshot for you to try it |
The snapshot is published (hopfeully:) |
Hi,and thanks a lot! I tested the snapshot and it worked fine, except for one test case i had. My tests look something like this: //This passes
@Test(expected=NullPropertyBeanException.class)
public void test_utils_read_through_non_nulls_2()
{
X bean = new X();
BeanUtils.getValue(bean, "nested.a");
}
//This fails with java.lang.Exception: Unexpected exception, expected<jodd.bean.exception.NullPropertyBeanException> but was<jodd.bean.exception.PropertyNotFoundBeanException>
@Test(expected=NullPropertyBeanException.class)
public void test_utils_write_through_nulls()
{
X bean = new X();
BeanUtils.setValue(bean, 5, "nested.a");
} |
Absolutely! Hold my beer... coding it :) |
Done, releasing during the day (need to migrate from travis, damn :( |
Snapshot published 🍭 |
Awesome! It works for me now. Many thanks. If you have time to do a specific snap for the jodd.bean-package, it would be cool! But i can wait for proper release too |
6.1.0 released :) |
Just a little followup. I've now been running BeanUtils and it works great =) Thanks a bunch |
Glad to hear so!!! |
Hi. And thanks for the nice lib.
I would like to be able to differentiate between accessing a nested property through null and an invalid nested property.
Consider following classes:
should give different exceptions in my opinion.
Since nested.b is a mistake in code, while nested.a is just cause nested is null.
Or if one wants keep same exception, perhaps a flag or a mode can be created to be able to differentiate these two cases.
The text was updated successfully, but these errors were encountered: