how to ignore a transient field

1,338 views
Skip to first unread message

Feu Teston

unread,
Apr 4, 2011, 3:54:04 PM4/4/11
to snakeya...@googlegroups.com
Hi!

I'm using SnakeYaml inside my projects for a few months. There's a place that I have a field that I don't want to be serialized. 
I looked for this topic (how to deal with transient fields) on wiki and also on the tickets, and the only thing about it that I found is in issue #55 on comment #13: 

"There is another situation - transient field with getter and setter. It is actually dumped in current implementation. (Could be avoided by providing correct BeanInfo). Maybe it is a topic for group discussion ;)"

So, what I need to know is: Is there anyway to ignore some transient field on SnakeYaml? Can anybody point me to some solution? Sorry, but I didn't get how to provide the correct BeanInfo.

I appreciate your help!

Best regards,



Teston

maslovalex

unread,
Apr 5, 2011, 2:34:13 AM4/5/11
to SnakeYAML
Hi.

You can use YAML.setBeanAccess(BeanAccess.FIELDS), but then neither
setter nor getter is used (only field access). It's not always
suitable.

About writing BeanInfo, this may help:
http://java.sun.com/developer/onlineTraining/Beans/Beans4/nervous06.html

-Alex

Andrey

unread,
Apr 5, 2011, 3:52:49 AM4/5/11
to snakeya...@googlegroups.com
Hi Feu,
you may try to override Representer.getProperties(Class<? extends Object> type).

Call super() and remove the property with the known name.

-
Andrey

Feu Teston

unread,
Apr 5, 2011, 8:00:26 AM4/5/11
to snakeya...@googlegroups.com
Hi!

Thanks for all of your folks for the fast answer! It worked pretty well :-)

Best regards!



Teston



2011/4/5 Andrey <py4...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "SnakeYAML" group.
To post to this group, send email to snakeya...@googlegroups.com.
To unsubscribe from this group, send email to snakeyaml-cor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/snakeyaml-core?hl=en.

Reply all
Reply to author
Forward
0 new messages