Repository: decorators-squad/eo-yaml
Pull request #417 (2020-10-31 10:18:25)

#231 Added + tested Yaml.fromJsonObject()
PR for  #231


Patch:
diff --git a/pom.xml b/pom.xml
index aa903d8..ff9b84e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,6 +43,17 @@
         <developerConnection>scm:git:git@github.com:decorators-squad/eo-yaml.git</developerConnection>
     </scm>
     <dependencies>
+        <dependency>
+            <groupId>javax.json</groupId>
+            <artifactId>javax.json-api</artifactId>
+            <version>1.1.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish</groupId>
+            <artifactId>javax.json</artifactId>
+            <version>1.1.4</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
diff --git a/src/main/java/com/amihaiemil/eoyaml/JsonYamlDump.java b/src/main/java/com/amihaiemil/eoyaml/JsonYamlDump.java
new file mode 100644
index 0000000..a28c92c
--- /dev/null
+++ b/src/main/java/com/amihaiemil/eoyaml/JsonYamlDump.java
@@ -0,0 +1,77 @@
+/**
+ * Copyright (c) 2016-2020, Mihai Emil Andronache
+ * All rights reserved.
+ * <p>
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+package com.amihaiemil.eoyaml;
+
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonValue;
+
+/**
+ * A YamlDump that works with javax-json-api.
+ * @author criske
+ * @version $Id$
+ * @since 5.1.7
+ */
+final class JsonYamlDump implements YamlDump {
+
+    /**
+     * JsonValue to dump.
+     */
+    private final JsonValue value;
+
+    /**
+     * Constructor.
+     *
+     * @param value JsonValue to dump.
+     */
+    JsonYamlDump(final JsonValue value) {
+        this.value = value;
+    }
+
+    @Override
+    public YamlNode dump() {
+        final YamlNode node;
+        final JsonValue safeValue;
+        if (this.value == null) {
+            safeValue = JsonValue.NULL;
+        } else {
+            safeValue = this.value;
+        }
+        if (safeValue instanceof JsonObject) {
+            node = new JsonYamlMapping((JsonObject) safeValue);
+        } else if (safeValue instanceof JsonArray) {
+            node = new JsonYamlSequence((JsonArray) safeValue);
+        } else {
+            node = new PlainStringScalar(safeValue
+                .toString()
+                .replace("\"", "")
+            );
+        }
+        return node;
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/com/amihaiemil/eoyaml/JsonYamlMapping.java b/src/main/java/com/amihaiemil/eoyaml/JsonYamlMapping.java
new file mode 100644
index 0000000..7cfff45
--- /dev/null
+++ b/src/main/java/com/amihaiemil/eoyaml/JsonYamlMapping.java
@@ -0,0 +1,57 @@
+package com.amihaiemil.eoyaml;
+
+import javax.json.JsonObject;
+import javax.json.JsonValue;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+/**
+ * Representation of a {@link javax.json.JsonObject} as YAML Mapping.
+ * @author criske
+ * @version $Id$
+ * @since 5.1.7
+ */
+final class JsonYamlMapping extends BaseYamlMapping {
+
+    /**
+     * Json object being mapped.
+     */
+    private final JsonObject object;
+
+    /**
+     * Ctor.
+     * @param object Json object being mapped.
+     */
+    JsonYamlMapping(final JsonObject object) {
+        this.object = object;
+    }
+
+    @Override
+    public Set<YamlNode> keys() {
+        final Set<YamlNode> keys = new LinkedHashSet<>();
+        this.object.keySet().forEach(key -> keys
+            .add(new PlainStringScalar(key)));
+        return keys;
+    }
+
+    @Override
+    public YamlNode value(final YamlNode key) {
+        final JsonValue jsonValue = this.object.get(key.asScalar().value());
+        return new JsonYamlDump(jsonValue).dump();
+    }
+
+    @Override
+    public Comment comment() {
+        return new Comment() {
+            @Override
+            public YamlNode yamlNode() {
+                return JsonYamlMapping.this;
+            }
+
+            @Override
+            public String value() {
+                return "";
+            }
+        };
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/com/amihaiemil/eoyaml/JsonYamlSequence.java b/src/main/java/com/amihaiemil/eoyaml/JsonYamlSequence.java
new file mode 100644
index 0000000..79245e3
--- /dev/null
+++ b/src/main/java/com/amihaiemil/eoyaml/JsonYamlSequence.java
@@ -0,0 +1,49 @@
+package com.amihaiemil.eoyaml;
+
+import javax.json.JsonArray;
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+/**
+ * Representation of a {@link javax.json.JsonArray} as YAML Sequence.
+ * @author criske
+ * @version $Id$
+ * @since 5.1.7
+ */
+final class JsonYamlSequence extends BaseYamlSequence {
+
+    /**
+     * Json array being mapped.
+     */
+    private final JsonArray array;
+
+    /**
+     * Ctor.
+     * @param array Json array being mapped.
+     */
+    JsonYamlSequence(final JsonArray array) {
+        this.array = array;
+    }
+
+    @Override
+    public Collection<YamlNode> values() {
+        return this.array.stream()
+            .map(value -> new JsonYamlDump(value).dump())
+            .collect(Collectors.toList());
+    }
+
+    @Override
+    public Comment comment() {
+        return new Comment() {
+            @Override
+            public YamlNode yamlNode() {
+                return JsonYamlSequence.this;
+            }
+
+            @Override
+            public String value() {
+                return "";
+            }
+        };
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/com/amihaiemil/eoyaml/Yaml.java b/src/main/java/com/amihaiemil/eoyaml/Yaml.java
index 7c26c46..4f7245b 100644
--- a/src/main/java/com/amihaiemil/eoyaml/Yaml.java
+++ b/src/main/java/com/amihaiemil/eoyaml/Yaml.java
@@ -27,6 +27,7 @@
  */
 package com.amihaiemil.eoyaml;
 
+import javax.json.JsonObject;
 import java.io.*;
 
 /**
@@ -34,7 +35,10 @@ import java.io.*;
  * @author Mihai Andronache (amihaiemil@gmail.com)
  * @version $Id$
  * @since 1.0.0
- *
+ * @todo #231:60min Implement and test method fromJsonArray(JsonArray)
+ *  for Yaml, that will create a YamlSequence from a JsonArray.
+ * @todo #231:60min Wiki documentation is needed for YAML mappings from JSON.
+ *  (fromJsonObject() and fromJsonArray()).
  */
 public final class Yaml {
 
@@ -181,4 +185,13 @@ public final class Yaml {
     public static YamlDump createYamlDump(final Object object) {
         return new ReflectedYamlDump(object);
     }
+
+    /**
+     * Create a YAML mapping from a {@link JsonObject}.
+     * @param object JsonObject in question.
+     * @return YamlMapping.
+     */
+    public static YamlMapping fromJsonObject(final JsonObject object) {
+        return new JsonYamlMapping(object);
+    }
 }


Test patch:
diff --git a/src/test/java/com/amihaiemil/eoyaml/JsonYamlDumpTest.java b/src/test/java/com/amihaiemil/eoyaml/JsonYamlDumpTest.java
new file mode 100644
index 0000000..4fe4c64
--- /dev/null
+++ b/src/test/java/com/amihaiemil/eoyaml/JsonYamlDumpTest.java
@@ -0,0 +1,72 @@
+/**
+ * Copyright (c) 2016-2020, Mihai Emil Andronache
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ *  list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright notice,
+ *  this list of conditions and the following disclaimer in the documentation
+ *  and/or other materials provided with the distribution.
+ * Neither the name of the copyright holder nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+package com.amihaiemil.eoyaml;
+
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+import javax.json.Json;
+
+/**
+ * Unit tests for {@link JsonYamlDump}.
+ * @author criske
+ * @version $Id$
+ * @since 5.1.7
+ */
+public final class JsonYamlDumpTest {
+
+    /**
+     * JsonYamlDump can dump null value.
+     */
+    @Test
+    public void canDumpNullValue(){
+        MatcherAssert.assertThat(new JsonYamlDump(null).dump(),
+            Matchers.equalTo(new PlainStringScalar("null")));
+    }
+
+    /**
+     * JsonYamlDump can dump JsonYamlMapping from json object.
+     */
+    @Test
+    public void canDumpJsonObject(){
+        MatcherAssert.assertThat(new JsonYamlDump(Json
+                .createObjectBuilder().build()).dump(),
+            Matchers.instanceOf(JsonYamlMapping.class));
+    }
+
+    /**
+     * JsonYamlDump can dump JsonYamlSequence from json array.
+     */
+    @Test
+    public void canDumpJsonArray(){
+        MatcherAssert.assertThat(new JsonYamlDump(Json
+                .createArrayBuilder().build()).dump(),
+            Matchers.instanceOf(JsonYamlSequence.class));
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/com/amihaiemil/eoyaml/JsonYamlMappingTest.java b/src/test/java/com/amihaiemil/eoyaml/JsonYamlMappingTest.java
new file mode 100644
index 0000000..fe03c17
--- /dev/null
+++ b/src/test/java/com/amihaiemil/eoyaml/JsonYamlMappingTest.java
@@ -0,0 +1,163 @@
+/**
+ * Copyright (c) 2016-2020, Mihai Emil Andronache
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ *  list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright notice,
+ *  this list of conditions and the following disclaimer in the documentation
+ *  and/or other materials provided with the distribution.
+ * Neither the name of the copyright holder nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+package com.amihaiemil.eoyaml;
+
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+import javax.json.Json;
+import javax.json.JsonObject;
+
+/**
+ * Unit tests for {@link JsonYamlMapping}.
+ * @author criske
+ * @version $Id$
+ * @since 5.1.7
+ */
+public final class JsonYamlMappingTest {
+
+    /**
+     * YamlMapping can map a json object to yaml object.
+     */
+    @Test
+    public void canMapJsonObject(){
+        final JsonObject json = Json.createObjectBuilder()
+            .add("architect", "mihai")
+            .add("developers",
+                Json.createArrayBuilder()
+                    .add("rultor")
+                    .add("salikjan")
+                    .add("sherif")
+                    .build()
+            )
+            .add("lib",
+                Json.createObjectBuilder()
+                    .add("name", "eo-yaml")
+                    .add("full-name", "")
+                    .add("version", 5)
+                    .build()
+            )
+            .add("notes", Json.createArrayBuilder().build())
+            .add("latest", false)
+            .build();
+        final YamlMapping expected = Yaml.createYamlMappingBuilder()
+            .add("architect", "mihai")
+            .add("developers",
+                Yaml.createYamlSequenceBuilder()
+                    .add("rultor")
+                    .add("salikjan")
+                    .add("sherif")
+                    .build()
+            )
+            .add("lib",
+                Yaml.createYamlMappingBuilder()
+                    .add("name", "eo-yaml")
+                    .add("full-name", "")
+                    .add("version", "5")
+                    .build()
+            )
+            .add("notes",  Yaml.createYamlSequenceBuilder().build())
+            .add("latest", "false")
+            .build();
+        final YamlMapping jsonMapping = new JsonYamlMapping(json);
+        MatcherAssert.assertThat(
+            jsonMapping.string("architect"),
+            Matchers.equalTo(expected.string("architect"))
+        );
+        MatcherAssert.assertThat(
+            jsonMapping.value("lib").asMapping().string("name"),
+            Matchers.equalTo(expected.value("lib").asMapping()
+                .string("name"))
+        );
+        MatcherAssert.assertThat(
+            jsonMapping.value("lib").asMapping().string("full-name"),
+            Matchers.equalTo(expected.value("lib").asMapping()
+                .string("full-name"))
+        );
+        MatcherAssert.assertThat(
+            jsonMapping.value("lib").asMapping().integer("version"),
+            Matchers.equalTo(expected.value("lib").asMapping()
+                .integer("version"))
+        );
+        MatcherAssert.assertThat(
+            jsonMapping.yamlSequence("notes").size(),
+            Matchers.equalTo(expected.yamlSequence("notes").size())
+        );
+        MatcherAssert.assertThat(
+            jsonMapping.yamlSequence("developers").size(),
+            Matchers.equalTo(expected.yamlSequence("developers").size())
+        );
+        MatcherAssert.assertThat(
+            jsonMapping.yamlSequence("developers").size(),
+            Matchers.equalTo(expected.yamlSequence("developers").size())
+        );
+        MatcherAssert.assertThat(
+            jsonMapping.yamlSequence("developers").string(0),
+            Matchers.equalTo(expected.yamlSequence("developers").string(0))
+        );
+        MatcherAssert.assertThat(
+            jsonMapping.yamlSequence("developers").string(1),
+            Matchers.equalTo(expected.yamlSequence("developers").string(1))
+        );
+        MatcherAssert.assertThat(
+            jsonMapping.yamlSequence("developers").string(2),
+            Matchers.equalTo(expected.yamlSequence("developers").string(2))
+        );
+        MatcherAssert.assertThat(
+            jsonMapping, Matchers.equalTo(expected)
+        );
+    }
+
+    /**
+     * YamlMapping can map an empty json object to yaml object.
+     */
+    @Test
+    public void canMapEmptyJsonObject(){
+        final JsonObject json = Json.createObjectBuilder().build();
+        final YamlMapping expected = Yaml.createYamlMappingBuilder().build();
+        MatcherAssert.assertThat(
+            new JsonYamlMapping(json), Matchers.equalTo(expected)
+        );
+    }
+
+    /**
+     * YamlMapping has empty Comment.
+     */
+    @Test
+    public void hasEmptyComment(){
+        final Comment comment = new JsonYamlMapping(Json
+            .createObjectBuilder()
+            .build())
+            .comment();
+        MatcherAssert.assertThat(comment.yamlNode(), Matchers
+            .instanceOf(JsonYamlMapping.class));
+        MatcherAssert.assertThat(comment.value(), Matchers
+            .isEmptyString());
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/com/amihaiemil/eoyaml/JsonYamlSequenceTest.java b/src/test/java/com/amihaiemil/eoyaml/JsonYamlSequenceTest.java
new file mode 100644
index 0000000..40591a4
--- /dev/null
+++ b/src/test/java/com/amihaiemil/eoyaml/JsonYamlSequenceTest.java
@@ -0,0 +1,77 @@
+/**
+ * Copyright (c) 2016-2020, Mihai Emil Andronache
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ *  list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright notice,
+ *  this list of conditions and the following disclaimer in the documentation
+ *  and/or other materials provided with the distribution.
+ * Neither the name of the copyright holder nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+package com.amihaiemil.eoyaml;
+
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+
+/**
+ * Unit tests for {@link JsonYamlSequence}.
+ * @author criske
+ * @version $Id$
+ * @since 5.1.7
+ */
+public final class JsonYamlSequenceTest {
+
+    /**
+     * JsonYamlSequence can map a json array.
+     */
+    @Test
+    public void canMapJsonArray(){
+        final JsonArray array =  Json.createArrayBuilder()
+            .add("rultor")
+            .add("salikjan")
+            .add("sherif")
+            .build();
+        final JsonYamlSequence sequence = new JsonYamlSequence(array);
+        MatcherAssert.assertThat(sequence.values(),
+            Matchers.iterableWithSize(3));
+        MatcherAssert.assertThat(sequence.values().iterator().next(),
+            Matchers.equalTo(new PlainStringScalar("rultor"))
+        );
+    }
+
+    /**
+     * JsonYamlSequence has empty Comment.
+     */
+    @Test
+    public void hasEmptyComment(){
+        final Comment comment = new JsonYamlSequence(Json
+            .createArrayBuilder()
+            .build())
+            .comment();
+        MatcherAssert.assertThat(comment.yamlNode(), Matchers
+            .instanceOf(JsonYamlSequence.class));
+        MatcherAssert.assertThat(comment.value(), Matchers
+            .isEmptyString());
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/com/amihaiemil/eoyaml/YamlTest.java b/src/test/java/com/amihaiemil/eoyaml/YamlTest.java
index 3870d53..20e40aa 100644
--- a/src/test/java/com/amihaiemil/eoyaml/YamlTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/YamlTest.java
@@ -34,6 +34,8 @@ import org.hamcrest.MatcherAssert;
 import org.hamcrest.Matchers;
 import org.junit.Test;
 
+import javax.json.Json;
+
 /**
  * Unit tests for {@link Yaml}.
  * @author Mihai Andronache (amihaiemil@gmail.com)
@@ -118,4 +120,15 @@ public final class YamlTest {
             Yaml.createYamlInput("yaml: test"), Matchers.notNullValue()
         );
     }
+
+    /**
+     * Yaml can create an YamlMapping from a json object.
+     */
+    @Test
+    public void createsYamlMappingFromJsonObject() {
+        MatcherAssert.assertThat(
+            Yaml.fromJsonObject(Json.createObjectBuilder().build()),
+            Matchers.notNullValue()
+        );
+    }
 }