All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.redis.riot.file.JsonLineAggregator Maven / Gradle / Ivy

There is a newer version: 4.1.9
Show newest version
package com.redis.riot.file;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.file.transform.LineAggregator;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonLineAggregator implements LineAggregator {

	private final Logger log = LoggerFactory.getLogger(getClass());

	private final ObjectMapper mapper;

	public JsonLineAggregator(ObjectMapper mapper) {
		this.mapper = mapper;
	}

	@Override
	public String aggregate(T item) {
		try {
			return mapper.writeValueAsString(item);
		} catch (JsonProcessingException e) {
			log.error("Cpuld not serialize item", e);
			return null;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy