Closed GoogleCodeExporter closed 9 years ago
Part of the problem is because I'm not clear on how to model array types in
JavaBeans.
Original comment by ashwin.j...@gmail.com
on 18 Sep 2009 at 10:21
Arrays are a very weak type:
1) at runtime the type of members is lost (byte[] looks the same as int[])
2) equals() and hashcode() and toString() leave much to be desired
3) Reflection API does not provide a lot of support
Because of these and other limitations arrays are not fully supported in
SnakeYAML.
Use Collections.
If you really want arrays support take a look at the source code and feel free
to
contribute a proposal.
Original comment by py4fun@gmail.com
on 19 Sep 2009 at 8:01
You will find that the array type is accessible as demonstrated by the sample
code:
=============
import java.lang.reflect.*;
import java.util.*;
public class Test{
String[] names;
int id;
HashMap something;
public static void main(String[] args){
Field[] fields = Test.class.getDeclaredFields();
System.out.println("Fields: " + fields.length);
for(Field f : fields){
System.out.println("Field: " + f.getName() + ", Type: " + f.getType() + ", Array:
" + f.getType().isArray());
}
}
}
=============
Result:
C:\_Dump\2\j>java Test
Fields: 3
Field: names, Type: class [Ljava.lang.String;, Array: true
Field: id, Type: int, Array: false
Field: something, Type: class java.util.HashMap, Array: false
=============
Notice the "[Ljava.lang.String" for "names".
Also, on the Sun JDK, the order of fields is preserved, even though the
JavaDocs says
that no field & method order is guaranteed. It should be true for most JDKs
too, I think.
Original comment by ashwin.j...@gmail.com
on 20 Sep 2009 at 7:12
And to do the reverse -
http://www.java2s.com/Code/Java/Language-Basics/ArrayReflectioncreateinstance.ht
m
Original comment by ashwin.j...@gmail.com
on 21 Sep 2009 at 5:30
I see the point now. I will have a look.
Original comment by py4fun@gmail.com
on 22 Sep 2009 at 3:51
Fixed: http://code.google.com/p/snakeyaml/wiki/readme#History
Original comment by py4fun@gmail.com
on 22 Sep 2009 at 4:19
Cool, that was quick!
Original comment by ashwin.j...@gmail.com
on 22 Sep 2009 at 5:15
Original issue reported on code.google.com by
ashwin.j...@gmail.com
on 18 Sep 2009 at 10:08