// Path: stardao-core/src/main/java/io/stardog/stardao/core/field/FieldData.java
// @AutoValue
// public abstract class FieldData {
//     @Nullable
//     public abstract Field getId();
//     @Nullable
//     public abstract Field getCreatedAt();
//     @Nullable
//     public abstract Field getCreatedBy();
//     @Nullable
//     public abstract Field getUpdatedAt();
//     @Nullable
//     public abstract Field getUpdatedBy();
//     public abstract Map<String,Field> getMap();
// 
//     public abstract Builder toBuilder();
//     public static FieldData.Builder builder() {
//         return new AutoValue_FieldData.Builder();
//     }
// 
//     @AutoValue.Builder
//     public abstract static class Builder {
//         public abstract Builder id(Field id);
//         public abstract Builder createdAt(Field field);
//         public abstract Builder createdBy(Field field);
//         public abstract Builder updatedAt(Field field);
//         public abstract Builder updatedBy(Field field);
//         public abstract Builder map(Map<String,Field> fields);
//         public abstract FieldData build();
//     }
// }
// 
// Path: stardao-dynamodb/src/main/java/io/stardog/stardao/dynamodb/mapper/JacksonItemMapper.java
// public class JacksonItemMapper<M> implements ItemMapper<M> {
//     private final Class<M> modelClass;
//     private final FieldData fieldData;
//     private final ObjectMapper objectMapper;
//     private final Map<String,String> objectToItemFieldRenames;
//     private final Map<String,String> itemToObjectFieldRenames;
// 
//     public JacksonItemMapper(Class<M> modelClass, FieldData fieldData) {
//         this(modelClass, fieldData, new ObjectMapper()
//                 .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
//                 .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true)
//                 .configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false)
//                 .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false)
//                 .registerModule(new Jdk8Module())
//                 .registerModule(new JavaTimeModule()));
//     }
// 
//     public JacksonItemMapper(Class<M> modelClass, FieldData fieldData, ObjectMapper objectMapper) {
//         this.modelClass = modelClass;
//         this.fieldData = fieldData;
//         this.objectMapper = objectMapper;
//         this.objectToItemFieldRenames = new HashMap<>();
//         this.itemToObjectFieldRenames = new HashMap<>();
//         for (Field field : fieldData.getMap().values()) {
//             if (!field.getStorageName().equals(field.getName())) {
//                 objectToItemFieldRenames.put(field.getName(), field.getStorageName());
//                 itemToObjectFieldRenames.put(field.getStorageName(), field.getName());
//             }
//         }
//     }
// 
//     public ObjectMapper getObjectMapper() {
//         return objectMapper;
//     }
// 
//     /**
//      * Map a DynamoDB Item to a POJO, using the Jackson object modelMapper.
//      * @param item  item to convert to a POJO
//      * @return  POJO representation of item
//      */
//     public M toObject(Item item) {
//         if (item == null) {
//             return null;
//         }
//         item = renameItem(item, itemToObjectFieldRenames);
//         Map<String,Object> map = item.asMap();
//         try {
//             String json = objectMapper.writeValueAsString(map);
//             return objectMapper.readValue(json, modelClass);
//         } catch (IOException e) {
//             throw new UncheckedIOException(e);
//         }
//     }
// 
//     /**
//      * Map a POJO to a DynamoDB Item, using the Jackson object modelMapper.
//      * @param object    POJO to convert to an item
//      * @return  item representation of POJO
//      */
//     public Item toItem(Object object) {
//         try {
//             String json = objectMapper.writeValueAsString(object);
//             Item item = Item.fromJSON(json);
// 
//             // remove any empty strings, since DynamoDB cannot store them
//             List<String> removeAttrs = new ArrayList<>();
//             for (Map.Entry<String,Object> attr : item.attributes()) {
//                 if ("".equals(attr.getValue())) {
//                     removeAttrs.add(attr.getKey());
//                 }
//             }
//             for (String attrName : removeAttrs) {
//                 item.removeAttribute(attrName);
//             }
// 
//             item = renameItem(item, objectToItemFieldRenames);
//             return item;
//         } catch (JsonProcessingException e) {
//             throw new IllegalArgumentException("Unable to convert " + object, e);
//         }
//     }
// 
//     protected Item renameItem(Item item, Map<String,String> renames) {
//         Map<String,Object> map = item.asMap();
//         Item renamedItem = new Item();
//         for (String key : map.keySet()) {
//             String renamedKey = renames.getOrDefault(key, key);
//             if (renamedKey != null && !"".equals(renamedKey)) {
//                 renamedItem.with(renamedKey, item.get(key));
//             }
//         }
//         return renamedItem;
//     }
// }


import com.amazonaws.services.dynamodbv2.document.Item;
import com.google.common.collect.ImmutableMap;
import io.stardog.stardao.core.field.FieldData;
import io.stardog.stardao.dynamodb.mapper.JacksonItemMapper;
import org.junit.Test;
import java.time.Instant;
import java.time.LocalDate;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
package io.stardog.stardao.dynamodb;




public class JacksonItemMapperTest {
    @Test
    public void testToItem() throws Exception {
// Path: stardao-core/src/main/java/io/stardog/stardao/core/field/FieldData.java
// @AutoValue
// public abstract class FieldData {
//     @Nullable
//     public abstract Field getId();
//     @Nullable
//     public abstract Field getCreatedAt();
//     @Nullable
//     public abstract Field getCreatedBy();
//     @Nullable
//     public abstract Field getUpdatedAt();
//     @Nullable
//     public abstract Field getUpdatedBy();
//     public abstract Map<String,Field> getMap();
// 
//     public abstract Builder toBuilder();
//     public static FieldData.Builder builder() {
//         return new AutoValue_FieldData.Builder();
//     }
// 
//     @AutoValue.Builder
//     public abstract static class Builder {
//         public abstract Builder id(Field id);
//         public abstract Builder createdAt(Field field);
//         public abstract Builder createdBy(Field field);
//         public abstract Builder updatedAt(Field field);
//         public abstract Builder updatedBy(Field field);
//         public abstract Builder map(Map<String,Field> fields);
//         public abstract FieldData build();
//     }
// }
// 
// Path: stardao-dynamodb/src/main/java/io/stardog/stardao/dynamodb/mapper/JacksonItemMapper.java
// public class JacksonItemMapper<M> implements ItemMapper<M> {
//     private final Class<M> modelClass;
//     private final FieldData fieldData;
//     private final ObjectMapper objectMapper;
//     private final Map<String,String> objectToItemFieldRenames;
//     private final Map<String,String> itemToObjectFieldRenames;
// 
//     public JacksonItemMapper(Class<M> modelClass, FieldData fieldData) {
//         this(modelClass, fieldData, new ObjectMapper()
//                 .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
//                 .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true)
//                 .configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false)
//                 .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false)
//                 .registerModule(new Jdk8Module())
//                 .registerModule(new JavaTimeModule()));
//     }
// 
//     public JacksonItemMapper(Class<M> modelClass, FieldData fieldData, ObjectMapper objectMapper) {
//         this.modelClass = modelClass;
//         this.fieldData = fieldData;
//         this.objectMapper = objectMapper;
//         this.objectToItemFieldRenames = new HashMap<>();
//         this.itemToObjectFieldRenames = new HashMap<>();
//         for (Field field : fieldData.getMap().values()) {
//             if (!field.getStorageName().equals(field.getName())) {
//                 objectToItemFieldRenames.put(field.getName(), field.getStorageName());
//                 itemToObjectFieldRenames.put(field.getStorageName(), field.getName());
//             }
//         }
//     }
// 
//     public ObjectMapper getObjectMapper() {
//         return objectMapper;
//     }
// 
//     /**
//      * Map a DynamoDB Item to a POJO, using the Jackson object modelMapper.
//      * @param item  item to convert to a POJO
//      * @return  POJO representation of item
//      */
//     public M toObject(Item item) {
//         if (item == null) {
//             return null;
//         }
//         item = renameItem(item, itemToObjectFieldRenames);
//         Map<String,Object> map = item.asMap();
//         try {
//             String json = objectMapper.writeValueAsString(map);
//             return objectMapper.readValue(json, modelClass);
//         } catch (IOException e) {
//             throw new UncheckedIOException(e);
//         }
//     }
// 
//     /**
//      * Map a POJO to a DynamoDB Item, using the Jackson object modelMapper.
//      * @param object    POJO to convert to an item
//      * @return  item representation of POJO
//      */
//     public Item toItem(Object object) {
//         try {
//             String json = objectMapper.writeValueAsString(object);
//             Item item = Item.fromJSON(json);
// 
//             // remove any empty strings, since DynamoDB cannot store them
//             List<String> removeAttrs = new ArrayList<>();
//             for (Map.Entry<String,Object> attr : item.attributes()) {
//                 if ("".equals(attr.getValue())) {
//                     removeAttrs.add(attr.getKey());
//                 }
//             }
//             for (String attrName : removeAttrs) {
//                 item.removeAttribute(attrName);
//             }
// 
//             item = renameItem(item, objectToItemFieldRenames);
//             return item;
//         } catch (JsonProcessingException e) {
//             throw new IllegalArgumentException("Unable to convert " + object, e);
//         }
//     }
// 
//     protected Item renameItem(Item item, Map<String,String> renames) {
//         Map<String,Object> map = item.asMap();
//         Item renamedItem = new Item();
//         for (String key : map.keySet()) {
//             String renamedKey = renames.getOrDefault(key, key);
//             if (renamedKey != null && !"".equals(renamedKey)) {
//                 renamedItem.with(renamedKey, item.get(key));
//             }
//         }
//         return renamedItem;
//     }
// }


// Path: stardao-dynamodb/src/test/java/io/stardog/stardao/dynamodb/JacksonItemMapperTest.java
import com.amazonaws.services.dynamodbv2.document.Item;
import com.google.common.collect.ImmutableMap;
import io.stardog.stardao.core.field.FieldData;
import io.stardog.stardao.dynamodb.mapper.JacksonItemMapper;
import org.junit.Test;
import java.time.Instant;
import java.time.LocalDate;
import java.util.UUID;
import static org.junit.Assert.assertEquals;

package io.stardog.stardao.dynamodb;




public class JacksonItemMapperTest {
    @Test
    public void testToItem() throws Exception {
        JacksonItemMapper<TestObject> mapper = new JacksonItemMapper<>(TestObject.class, FieldData.builder().map(ImmutableMap.of()).build());