HELP: Unable to find property

301 views
Skip to first unread message

Wafa Ketata

unread,
Jun 3, 2016, 2:21:20 PM6/3/16
to yamlbeans-users
I'm looking to deserialize yaml file where the type of variable in the yaml file is different from my class.
I attached my example foo.java and my main method.
I'm getting the next error:
Exception in thread "main" com.esotericsoftware.yamlbeans.YamlReader$YamlReaderException: Line 0, column 9: Unable to find property 'fooBytes' on class: com.yamlTest.foo

what wrong ?
I need to use "String getFooBytes()" and I can't change the type of "byte[] fooBytes"
And How can I do it ?

package com.yamlTest;

import java.io.UnsupportedEncodingException;

public class foo {
    private byte[] fooBytes;

    public String getFooBytes() {
        return getStringFromUTF8Bytes(fooBytes);
    }

    public void setFooBytes(String string) {
        fooBytes = getUTF8Bytes(string);
    }

    private static final byte[] getUTF8Bytes(String string) {
        if (string == null)
            return null;
        try {
            return string.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            return null;
        }
    }

    private static final String getStringFromUTF8Bytes(byte[] bytes) {
        if (bytes == null)
            return null;
        try {
            return new String(bytes, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            return null;
        }
    }
}


public static void main(String[] args) throws FileNotFoundException, YamlException {
    // TODO Auto-generated method stub
    File f = new File("data/foo.yml");
    YamlReader reader = new YamlReader(new FileReader(f));
    foo fo = reader.read(foo.class);
    System.out.println(fo.getFooBytes());
}

//my file foo.yml

fooBytes: NewYork



Nate

unread,
Jun 3, 2016, 2:45:01 PM6/3/16
to yamlbea...@googlegroups.com
See Beans#getProperty. It uses the type of fields to look for a matching getter and setter. Your field is byte[] so it looks for setFooBytes(byte[]) and byte[] getFooBytes.

That is a bit lame so I just committed better bean property lookup which will work with your code.

Cheers,
-Nate

--
--
You received this message because you are subscribed to the "yamlbeans-users" group:
http://groups.google.com/group/yamlbeans-users

---
You received this message because you are subscribed to the Google Groups "yamlbeans-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yamlbeans-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages