0

I am working on a simple project where I need to write person data into a yaml file . I am using yamlbeans to serialize and de-serialize the data. I specifically want all the java bean properties to be String. Here's how my bean properties looks like:

        String employeeID;
        String firstName;
        String lastName;
        String email;
        List<String> activities;
        List<String> skills;
        String comments;
        List<String> contracts;
        String seniority        
        String endDate;
        String hourlyWage;
        String startDate;
        String teamName;

I was able to successfully write a yaml file with the following example values:

!PersonBean
comments: ' '
contracts: []
email: first.last@email.com
employeeID: 12344
endDate: 12/30/1899
firstName: John
hourlyWage: 45
lastName: Doe
seniority: 0
siteName: Toronto
skills: 
- Technical
- Test
startDate: 1/14/2019

However when I am trying to read the file using YamlReader, I get an error message showing Expected data for a com.example field but found: scalar. I can see the created yaml file writes the hourlywage / employee id/ Seniorty as ints and not strings

I have read multiple posts related to this problem and couldn't find a conclusive solution. Here's my question:

I want my bean properties to stay string (this is a must), So I would like to know: - Is there a way to write all the values as strings (I have tried surrounding them with quotes, and I get the same error message while reading the file) - (OR) Is there a way to read those ints as strings while using the YamlReader?

Thanks in advance for any pointers/solutions! Cheers!

wicke_s
  • 33
  • 5
  • Welcome to SO! You need to provide the code you use for (de-)serialization so that others can see what you're actually doing – please edit your question to include that code. The error message you get indicates that your issue is not about the numbers (both ints and strings are scalars in YAML, and a scalar that looks like a number may still be parsed as string. While I do not know yamlbeans, I assume based on its maturity that it is able to properly load serialized data it has written and your problem is somewhere else. – flyx Jan 23 '19 at 10:54
  • You're right. The error is kinda misleading, but I found the issue somewhere else in my code and fixed it. I do appreciate you taking the time to respond. Thank You! – wicke_s Jan 26 '19 at 14:56

0 Answers0