Is there a good yaml library for Android?

Is java yaml library as good as snakeyaml for Android? (Or does anyone successfully use snakeyaml on Android already?)

+7
java android yaml
source share
3 answers

I do not think that you can use SnakeYaml on Android without changes (at least for now).

By default, SnakeYaml uses the Introspector to get PropertyDescriptors for classes, and as I see it, java.beans.Introspector not available on Android. But there is BeanAccess.FEILD mode in SnakeYaml that uses fields to reset / load beans. This mode uses only java.lang.reflect tags available on Android.

So, with some changes, this might work. But I need to try to be sure.

Added

Now the Android compatible version of SnakeYaml can be built using:

mvn -Pandroid clean package

Update (March 2017):

Starting with version 1.18, the Android assembly is in the center. You can add a dependency to your pom.xml like this

 <dependency> <groupId>org.yaml</groupId> <artifactId>snakeyaml</artifactId> <version> VERSION </version> <classifier>android</classifier> </dependency> 
+5
source share

I think you should at least try straight snakeyaml. For this type of library, it is highly likely that the required Java API suite is available on Android.

If it does not work, you can try importing the snakeyaml source code into the android project and see what does not compile. With little luck, you will be able to get around the missing APIs.

0
source share

From the answer How can I convert from YAML to JSON in Java?

 String convertYamlToJson(String yaml) { ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory()); Object obj = yamlReader.readValue(yaml, Object.class); ObjectMapper jsonWriter = new ObjectMapper(); return jsonWriter.writeValueAsString(obj); } 

It is required:

 implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.7.4' 
0
source share

All Articles