how to get an empty Object Array (Object[0])?

43 views
Skip to first unread message

ryez

unread,
Feb 14, 2012, 2:35:47 AM2/14/12
to snakeya...@googlegroups.com
e.g

---
defaultValues: []

I want the above yaml leads to defaultValues == new Object[0].
I've tried with [], !!seq [], all lead to null, any idea?

Thanks

Andrey

unread,
Feb 14, 2012, 4:55:48 AM2/14/12
to snakeya...@googlegroups.com
Hi,
Let us clarify the request to see its scope.

1) An empty sequence should create an empty List. If you get 'null' instead please report a bug. (The difference between empty list and 'null' is very important)

2) Java Reflection API has very bad support for arrays. You may create lists and then transform them to any structure inside your business code. If you wish to create arrays directly, get prepared for a lot of surprises. 

3) Do you always expect empty sequence to become an array ? Do you always expect any sequence to become an array ?
If yes, you may extend Constructor:

You have to provide your own way to create a sequence:
yamlClassConstructors.put(NodeId.sequence, new ConstructSequence()); 

4) You may also use a JavaBean. When you define arrays as JavaBean properties then SnakeYAML has runtime information about the class and it can help you create the expected array.

I hope it helps,
Andrey



Reply all
Reply to author
Forward
0 new messages