Serhii Shevchyk
Serhii Shevchyk

Reputation: 39436

How to convert String data into byte array using YAML library?

What I want to have is YAML configuration file, where I would be able to write pre-loaded data for database.

I'd like to have such config:

- books
  - !org.test.Book
    - name: TestName 
    - description: TestDescription
    - isbn: 960-425-059-0

Moreover, I would like to have a possibility to convert isbn String field into the byte array field

of Book class(or any other data type).

  class Book{
    private String name;
    private String description;
    private byte[] isbn;
  }

Is there any suitable YAML library for Java?

Upvotes: 1

Views: 3047

Answers (1)

Renaud Mathieu
Renaud Mathieu

Reputation: 376

Java Yaml libraries:

JYaml

Yamlbeans

You can still convert your byte array to String with a special encoding (that you should know). The way to convert it to a String is:

String decoded = new String(bytes, "UTF-8");  // example for one encoding type

Upvotes: 1

Related Questions