package org.rundeck.storage.data.file;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
 * $INTERFACE is ... User: greg Date: 2/18/14 Time: 11:12 AM
 */
public class JsonMetadataMapper implements MetadataMapper {
    private ObjectMapper objectMapper;

    public JsonMetadataMapper() {
        objectMapper = new ObjectMapper();
    }

    public JsonMetadataMapper(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }


    @Override
    public void writeMetadata(Map<String, String> meta, File destination) throws IOException {
        if (!destination.getParentFile().exists()) {
            destination.getParentFile().mkdirs();
        }
        objectMapper.writeValue(destination, meta);
    }

    @Override
    @SuppressWarnings("unchecked")
    public Map<String, String> readMetadata(File metadata) throws IOException {
        return objectMapper.readValue(metadata, Map.class);
    }
}

@@ -135,16 +135,72 @@
 eption;%0A
+import java.util.Collections;%0Aimport java.util.HashMap;%0A
 import j
@@ -978,32 +978,67 @@
 s IOException %7B%0A
+        if(metadata.isFile())%7B%0A    
         return o
@@ -1081,16 +1081,102 @@
 class);%0A
+        %7D else %7B%0A            return Collections.%3CString, String%3EemptyMap();%0A        %7D%0A
     %7D%0A%7D%0A

Return empty map if Json metadatafile does not exist