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

name.valery1707.smsc.JsonMapperJackson Maven / Gradle / Ivy

The newest version!
package name.valery1707.smsc;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.type.CollectionType;

import java.io.IOException;
import java.util.List;

public class JsonMapperJackson implements JsonMapper {
	private final ObjectMapper mapper;

	public JsonMapperJackson() {
		mapper = new ObjectMapper()
				.findAndRegisterModules()
				.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
	}

	@Override
	public  T single(String json, Class clazz) throws IOException {
		return mapper.readValue(json, clazz);
	}

	@Override
	public  List multi(String json, Class clazz) throws IOException {
		CollectionType type = mapper.getTypeFactory().constructCollectionType(List.class, clazz);
		return mapper.readValue(json, type);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy