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.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.Test;

@Test
public class ObjectMapperTest {

    private ObjectMapper objectMapper;
    private JsonParser parser;

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

    public void shouldSerializeUsingJacksonObjectMapper() throws IOException {
        JsonObject o = 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)))
        );
        String serialized = objectMapper.writeValueAsString(o);
        assertThat(parser.parse(serialized)).isEqualTo(o);
        JsonObject deSerialized = objectMapper.readValue(serialized, JsonObject.class);
        assertThat(deSerialized).isEqualTo(o);
        System.err.println(deSerialized.prettyPrint());
    }
}

@@ -132,16 +132,77 @@
 .field;%0A
+import static com.github.jsonj.tools.JsonBuilder.fromObject;%0A
 import s
@@ -246,24 +246,24 @@
 der.object;%0A
-
 import stati
@@ -475,16 +475,60 @@
 Method;%0A
+import org.testng.annotations.DataProvider;%0A
 import o
@@ -804,114 +804,114 @@
     
-public void shouldSerializeUsingJacksonObjectMapper() throws IOException %7B%0A        JsonObject o = 
+@DataProvider%0A    public Object%5B%5D%5B%5D jsonElements() %7B%0A        return new Object%5B%5D%5B%5D %7B%0A            %7B
 object(%0A
     
@@ -906,16 +906,20 @@
 object(%0A
+    
         
@@ -959,24 +959,28 @@
             
+    
 field(%22a%22,42
@@ -984,16 +984,20 @@
 ,42.0),%0A
+    
         
@@ -1025,24 +1025,28 @@
             
+    
 field(%22c%22,ar
@@ -1084,24 +1084,28 @@
             
+    
 field(%22d%22,ob
@@ -1132,18 +1132,388 @@
         
+ 
-);
+   )%7D,%0A            %7B%0A                array(42,%22foo%22,3.14,true,null)%0A            %7D,%0A            %7B%0A                fromObject(42)%0A            %7D,%0A            %7B%0A                fromObject(%22hello world%22)%0A            %7D%0A        %7D;%0A    %7D%0A%0A    @Test(dataProvider=%22jsonElements%22)%0A    public void shouldSurviveSerializeDeserializeAndBeEqual(JsonElement element) throws IOException %7B
 %0A       
@@ -1565,17 +1565,23 @@
 sString(
-o
+element
 );%0A     
@@ -1622,33 +1622,39 @@
 zed)).isEqualTo(
-o
+element
 );%0A        JsonO
@@ -1652,21 +1652,22 @@
     Json
-Objec
+Elemen
 t deSeri
@@ -1776,65 +1776,15 @@
 lTo(
-o);%0A        System.err.println(deSerialized.prettyPrint()
+element
 );%0A 

improve object mapper test