package com.github.jsonj;

import static com.github.jsonj.tools.JsonBuilder.array;
import static com.github.jsonj.tools.JsonBuilder.field;
import static com.github.jsonj.tools.JsonBuilder.fromObject;
import static com.github.jsonj.tools.JsonBuilder.object;
import static org.assertj.core.api.Assertions.assertThat;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.jsonj.tools.JsonParser;
import java.io.IOException;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

@Test
public class ObjectMapperTest {

    private ObjectMapper objectMapper;
    private JsonParser parser;

    @BeforeMethod
    public void before() {
        objectMapper = new ObjectMapper();
        parser = new JsonParser();
    }

    @DataProvider
    public Object[][] jsonElements() {
        return new Object[][] {
            {object(
                field("meaning_of_life",42),
                field("a",42.0),
                field("b",true),
                field("c",array(42,"foo",3.14,true,null)),
                field("d",object(field("a",1)))
            )},
            {
                array(42,"foo",3.14,true,null)
            },
            {
                fromObject(42)
            },
            {
                fromObject("hello world")
            }
        };
    }

    @Test(dataProvider="jsonElements")
    public void shouldSurviveSerializeDeserializeAndBeEqual(JsonElement element) throws IOException {
        String serialized = objectMapper.writeValueAsString(element);
        assertThat(parser.parse(serialized)).isEqualTo(element);
        JsonElement deSerialized = objectMapper.readValue(serialized, JsonObject.class);
        assertThat(deSerialized).isEqualTo(element);
    }
}

@@ -1709,16 +1709,353 @@
 ialized,
+ JsonElement.class);%0A        assertThat(deSerialized).isEqualTo(element);%0A%0A        if(element.isArray()) %7B%0A            JsonArray e = objectMapper.readValue(serialized, JsonArray.class);%0A            assertThat(e).isEqualTo(element);%0A        %7D%0A%0A        if(element.isObject()) %7B%0A            JsonObject e = objectMapper.readValue(serialized,
  JsonObj
@@ -2066,32 +2066,36 @@
 class);%0A        
+    
 assertThat(deSer
@@ -2085,36 +2085,205 @@
  assertThat(
-deSerialized
+e).isEqualTo(element);%0A        %7D%0A%0A        if(element.isPrimitive()) %7B%0A            JsonPrimitive e = objectMapper.readValue(serialized, JsonPrimitive.class);%0A            assertThat(e
 ).isEqualTo(
@@ -2288,20 +2288,31 @@
 o(element);%0A
+        %7D%0A%0A
     %7D%0A%7D%0A

improve test