package dk.lessismore.nojpa.rest;

import dk.lessismore.nojpa.reflection.db.model.ModelObjectInterface;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.GenericConverter;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * Created by niakoi on 12/3/15.
 */
public class NoJpaConverter implements GenericConverter {

    protected Log log = LogFactory.getLog(getClass());

    private NoJpaFormatter formatter;

    public NoJpaConverter(NoJpaFormatter formatter) {
        this.formatter = formatter;
    }

    @Override
    public Set<ConvertiblePair> getConvertibleTypes() {
        Set<ConvertiblePair> pairs = new LinkedHashSet<ConvertiblePair>(2);
        pairs.add(new ConvertiblePair(formatter.getClazz(), String.class));
        pairs.add(new ConvertiblePair(String.class, formatter.getClazz()));
        return pairs;
    }

    @Override
    public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
        if (sourceType.getType().equals(String.class)) {
            return formatter.parse((String) source, null);
        } else {
            return formatter.print((ModelObjectInterface) source, null);
        }
        return null;
    }
}

@@ -307,16 +307,49 @@
 erter;%0A%0A
+import java.text.ParseException;%0A
 import j
@@ -1178,24 +1178,46 @@
 g.class)) %7B%0A
+            try %7B%0A    
             
@@ -1255,32 +1255,134 @@
  source, null);%0A
+            %7D catch (ParseException e) %7B%0A                throw new RuntimeException(e);%0A            %7D%0A
         %7D else %7B
@@ -1447,32 +1447,32 @@
  source, null);%0A
+
         %7D%0A      
@@ -1469,29 +1469,8 @@
   %7D%0A
-        return null;%0A
     

fix build