Example usage for org.springframework.data.repository.init Jackson2ResourceReader readFrom

List of usage examples for org.springframework.data.repository.init Jackson2ResourceReader readFrom

Introduction

In this page you can find the example usage for org.springframework.data.repository.init Jackson2ResourceReader readFrom.

Prototype

public Object readFrom(Resource resource, @Nullable ClassLoader classLoader) throws Exception 

Source Link

Usage

From source file:example.springdata.mongodb.util.BlogPostInitializer.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private void loadFromClasspathSource(MongoOperations operations) throws Exception {

    Jackson2ResourceReader reader = new Jackson2ResourceReader();

    Object source = reader.readFrom(new ClassPathResource("spring-blog.atom.json"),
            this.getClass().getClassLoader());

    if (source instanceof Iterable) {
        ((Iterable) source).forEach(element -> operations.save(element));
    } else {/*from  w  w w  .  jav  a  2 s  . c om*/
        operations.save(source);
    }

    log.info("Imported blog posts from classpath!");
}