/*
 * MIT License
 *
 * Copyright (c) 2017 Dennis Neufeld
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package space.npstr.sqlsauce.converters;

import org.postgresql.util.HStoreConverter;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.util.Map;

/**
 * Created by napster on 07.07.17.
 * <p>
 * Glue between JPA and postgres's hstore extension
 * When using this, you will likely need to set "stringtype" to "unspecified" in your JDBC url/parameters
 * You also need to enable the postgres hstore extension with
 * <p>
 * CREATE EXTENSION hstore;
 * <p>
 * for each database you want to use it in.
 */
@Converter(autoApply = true)
public class PostgresHStoreConverter implements AttributeConverter<Map<String, String>, String> {

    @Override
    public String convertToDatabaseColumn(final Map<String, String> attribute) {
        return HStoreConverter.toString(attribute);
    }

    @Override
    public Map<String, String> convertToEntityAttribute(final String dbData) {
        return HStoreConverter.fromString(dbData);
    }
}

@@ -1218,16 +1218,50 @@
 erter;%0A%0A
+import javax.annotation.Nullable;%0A
 import j
@@ -1846,32 +1846,46 @@
 %0A%0A    @Override%0A
+    @Nullable%0A
     public Strin
@@ -1910,16 +1910,26 @@
 eColumn(
+@Nullable 
 final Ma
@@ -1955,24 +1955,92 @@
 ttribute) %7B%0A
+        if (attribute == null) %7B%0A            return null;%0A        %7D%0A
         retu
@@ -2096,24 +2096,38 @@
   @Override%0A
+    @Nullable%0A
     public M
@@ -2170,16 +2170,26 @@
 tribute(
+@Nullable 
 final St
@@ -2199,24 +2199,89 @@
 g dbData) %7B%0A
+        if (dbData == null) %7B%0A            return null;%0A        %7D%0A
         retu

Make Hstore converter support null values