package org.hisp.dhis.system.util;

/*
 * Copyright (c) 2004-2017, University of Oslo
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * Neither the name of the HISP project nor the names of its contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

import java.io.IOException;
import java.io.UncheckedIOException;

/**
 * @author Lars Helge Overland
 */
public class JacksonUtils
{
    private final static ObjectMapper jsonMapper = new ObjectMapper();

    static
    {
        jsonMapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS );
        jsonMapper.disable( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS );
        jsonMapper.disable( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES );
        jsonMapper.setSerializationInclusion( JsonInclude.Include.NON_NULL );
    }

    public static <T> T fromJson( byte[] src, Class<T> clazz )
    {
        try
        {
            return jsonMapper.readValue( src, clazz );
        }
        catch ( IOException ex )
        {
            throw new UncheckedIOException( ex );
        }
    }
    
    public static <T> T fromJson( String string, Class<T> clazz )
    {
        try
        {
            return jsonMapper.readValue( string, clazz );
        }
        catch ( IOException ex )
        {
            throw new UncheckedIOException( ex );
        }
    }
    
    public static <T> String toJson( T object )
    {
        try
        {
            return jsonMapper.writeValueAsString( object );
        }
        catch ( IOException ex )
        {
            throw new UncheckedIOException( ex );
        }
    }
}

@@ -1640,16 +1640,70 @@
 nclude;%0A
+import com.fasterxml.jackson.core.type.TypeReference;%0A
 import c
@@ -1933,16 +1933,64 @@
 ception;
+%0Aimport java.util.HashMap;%0Aimport java.util.Map;
 %0A%0A/**%0A *
@@ -2997,32 +2997,293 @@
    %7D%0A    %7D%0A    %0A
+    public static %3CT, U%3E Map%3CT, U%3E fromJsonAsMap( String object )%0A        throws IOException%0A    %7B%0A        TypeReference%3CHashMap%3CT, U%3E%3E typeRef = new TypeReference%3CHashMap%3CT, U%3E%3E() %7B%7D;%0A        %0A        return jsonMapper.readValue( object, typeRef );%0A    %7D%0A    %0A
     public stati

Support method