Closed GoogleCodeExporter closed 9 years ago
Can't figure out how to make this an Enhancement request, sorry.
Original comment by obast...@gmail.com
on 11 Feb 2010 at 9:54
It seems an important feature: to exclude JavaBean properties based on some
runtime
criteria.
Do you have an idea how the API should look like ?
Original comment by py4fun@gmail.com
on 12 Feb 2010 at 9:10
I'm of two thoughts here.
First is simple:
representJavaBeanProperty(Object javaBean, Property property, Object
javaBeanValue)
Move the contents of the for loop into the method, then loop over the method
call. It's then trivial to just look
at the value and filter whether you call super. representJavaBeanProperty or
not.
Second is slightly different:
representJavaBeanProperties(Object javaBean, List<Property> properties)
Virtue of the second is that in my case, I want to filter out both nulls (easy
with the first) and default values
(more complex with the first because I have to build an empty object and
compare the values).
But I suspect #1 is the way to go, if you tweak the original to look like #1, I
can just add a lazily built cache in
a map of "blank" objects to compare against for default values.
Original comment by obast...@gmail.com
on 12 Feb 2010 at 3:27
>representJavaBeanProperty(Object javaBean, Property property, Object
javaBeanValue)
But how the COMPLETE solution should look like?
I mean how to create the Yaml instance and what should be the custom code ?
If you intend to overwrite the Representer then you can do it now and we do not
need
the API.
Original comment by py4fun@gmail.com
on 12 Feb 2010 at 5:34
The issue is that the method you have to override is large and complex, so if
you override all of
representJavaBean its fragile.
If you moved the contents of the properties loop to
representJavaBeanProperty(Object javaBean, Property
property, Object javaBeanValue), then a "null filter" would be:
public void representJavaBeanProperty(Object javaBean, Property property,
Object javaBeanValue)
{
if (javaBeanValue !=null) super. representJavaBeanProperty(javaBean,property,javaBeanValue)
}
Original comment by obast...@gmail.com
on 12 Feb 2010 at 6:35
Finally I understand what you mean. I have just made the change.
Please have a look:
http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyam
l/issues/issue48/SkipJavaBeanPropertyTest.java
Thank you for the idea.
Original comment by aso...@gmail.com
on 12 Feb 2010 at 9:10
Looks great.
Original comment by obast...@gmail.com
on 12 Feb 2010 at 9:19
It will be included in version 1.6
Original comment by aso...@gmail.com
on 12 Feb 2010 at 11:06
Original issue reported on code.google.com by
obast...@gmail.com
on 11 Feb 2010 at 9:53