package de.pbauerochse.worklogviewer.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.Reader;

/**
 * @author Patrick Bauerochse
 * @since 14.04.15
 */
public class JacksonUtil {

    private static ObjectMapper objectMapper = new ObjectMapper();

    public static String writeObject(Object object) throws JsonProcessingException {
        return objectMapper.writer().writeValueAsString(object);
    }

    public static <T> T parseValue(Reader contentReader, Class<T> tClass) throws IOException {
        return objectMapper.readValue(contentReader, tClass);
    }

    public static <T> T parseValue(Reader contentReader, TypeReference<T> typeReference) throws IOException {
        return objectMapper.readValue(contentReader, typeReference);
    }
}

@@ -37,16 +37,62 @@
 .util;%0A%0A
+import com.fasterxml.jackson.core.JsonParser;%0A
 import c
@@ -180,284 +180,1717 @@
 ore.
-type.TypeReference;%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0A%0Aimport java.io.IOException;%0Aimport java.io.Reader;%0A%0A/**%0A * @author Patrick Bauerochse%0A * @since 14.04.15%0A */%0Apublic class JacksonUtil %7B%0A%0A    private static ObjectMapper objectMapper = new ObjectMapper();
+ObjectCodec;%0Aimport com.fasterxml.jackson.core.Version;%0Aimport com.fasterxml.jackson.core.type.TypeReference;%0Aimport com.fasterxml.jackson.databind.DeserializationContext;%0Aimport com.fasterxml.jackson.databind.JsonDeserializer;%0Aimport com.fasterxml.jackson.databind.JsonNode;%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport com.fasterxml.jackson.databind.module.SimpleModule;%0Aimport de.pbauerochse.worklogviewer.youtrack.issuedetails.IssueField;%0A%0Aimport java.io.IOException;%0Aimport java.io.Reader;%0A%0A/**%0A * @author Patrick Bauerochse%0A * @since 14.04.15%0A */%0Apublic class JacksonUtil %7B%0A%0A    private static ObjectMapper objectMapper = new ObjectMapper();%0A    static %7B%0A        SimpleModule customModule = new SimpleModule(%22IssueField%22, new Version(1, 0, 0, null, null, null))%0A                .addDeserializer(IssueField.class, new JsonDeserializer%3CIssueField%3E() %7B%0A                    @Override%0A                    public IssueField deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)%0A                            throws IOException %7B%0A                        ObjectCodec oc = jsonParser.getCodec();%0A                        JsonNode node = oc.readTree(jsonParser);%0A                        IssueField result = new IssueField();%0A                        String name = node.get(%22name%22).asText();%0A                        result.setName(name);%0A                        JsonNode valueNode = node.get(%22value%22);%0A                        String value = valueNode.isTextual() ? valueNode.asText() : %220%22;%0A                        result.setValue(value);%0A                        return result;%0A                    %7D%0A                %7D);%0A        objectMapper.registerModule(customModule);%0A    %7D
 %0A%0A  

Fix for #20