// Path: spring-jdbc/src/main/java/io/crate/spring/jdbc/samples/dao/JDBCDBObjectsFactory.java
// public interface JDBCDBObjectsFactory {
// 
//     Object createUserObject(final BlogPost post);
// }
// 
// Path: spring-jdbc/src/main/java/io/crate/spring/jdbc/samples/dao/PostgresJDBCDBObjectsFactory.java
// public class PostgresJDBCDBObjectsFactory implements JDBCDBObjectsFactory {
// 
//     private ObjectMapper mapper = new ObjectMapper();
// 
//     @Override
//     public Object createUserObject(BlogPost post) {
//         if (post != null && post.getUser() != null) {
//             // objects can be streamed as json strings,
//             // https://crate.io/docs/reference/en/latest/protocols/postgres.html#jdbc
//             var userObject = new PGobject();
//             userObject.setType("json");
//             var userValue = new HashMap<String, Object>();
//             userValue.put("name", post.getUser().getName());
//             var locValues = new ArrayList<Double>();
//             locValues.add(post.getUser().getLat());
//             locValues.add(post.getUser().getLon());
//             userValue.put("location", locValues);
//             try {
//                 userObject.setValue(mapper.writeValueAsString(userValue));
//             } catch (JsonProcessingException | SQLException e) {
//                 throw new DataIntegrityViolationException("Can not create Postgres object for user", e);
//             }
//             return userObject;
//         } else
//             return null;
//     }
// }


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import io.crate.spring.jdbc.samples.dao.JDBCDBObjectsFactory;
import io.crate.spring.jdbc.samples.dao.PostgresJDBCDBObjectsFactory;
package io.crate.spring.jdbc.samples;



@SpringBootApplication
public class BackEndApplication {

    public static void main(String[] args) {
        SpringApplication.run(BackEndApplication.class, args);
    }

    @Bean
    public BlogPostSerializer createPostsSerializer() {
        return new BlogPostSerializer();
    }

    @Bean
    public BlogPostDeserializer createPostsDeserializer() {
        return new BlogPostDeserializer();
    }

    @Bean
    public JDBCDBObjectsFactory createObjectsFactory() {
// Path: spring-jdbc/src/main/java/io/crate/spring/jdbc/samples/dao/JDBCDBObjectsFactory.java
// public interface JDBCDBObjectsFactory {
// 
//     Object createUserObject(final BlogPost post);
// }
// 
// Path: spring-jdbc/src/main/java/io/crate/spring/jdbc/samples/dao/PostgresJDBCDBObjectsFactory.java
// public class PostgresJDBCDBObjectsFactory implements JDBCDBObjectsFactory {
// 
//     private ObjectMapper mapper = new ObjectMapper();
// 
//     @Override
//     public Object createUserObject(BlogPost post) {
//         if (post != null && post.getUser() != null) {
//             // objects can be streamed as json strings,
//             // https://crate.io/docs/reference/en/latest/protocols/postgres.html#jdbc
//             var userObject = new PGobject();
//             userObject.setType("json");
//             var userValue = new HashMap<String, Object>();
//             userValue.put("name", post.getUser().getName());
//             var locValues = new ArrayList<Double>();
//             locValues.add(post.getUser().getLat());
//             locValues.add(post.getUser().getLon());
//             userValue.put("location", locValues);
//             try {
//                 userObject.setValue(mapper.writeValueAsString(userValue));
//             } catch (JsonProcessingException | SQLException e) {
//                 throw new DataIntegrityViolationException("Can not create Postgres object for user", e);
//             }
//             return userObject;
//         } else
//             return null;
//     }
// }


// Path: spring-jdbc/src/main/java/io/crate/spring/jdbc/samples/BackEndApplication.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import io.crate.spring.jdbc.samples.dao.JDBCDBObjectsFactory;
import io.crate.spring.jdbc.samples.dao.PostgresJDBCDBObjectsFactory;

package io.crate.spring.jdbc.samples;



@SpringBootApplication
public class BackEndApplication {

    public static void main(String[] args) {
        SpringApplication.run(BackEndApplication.class, args);
    }

    @Bean
    public BlogPostSerializer createPostsSerializer() {
        return new BlogPostSerializer();
    }

    @Bean
    public BlogPostDeserializer createPostsDeserializer() {
        return new BlogPostDeserializer();
    }

    @Bean
    public JDBCDBObjectsFactory createObjectsFactory() {
        return new PostgresJDBCDBObjectsFactory();