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

org.springframework.social.partnercenter.serialization.JsonSerializationSettings Maven / Gradle / Ivy

Go to download

A provider extension for Spring Social to enable connectivity with Microsoft and an API binding for Microsoft's Partner Center API.

There is a newer version: 10.11.0
Show newest version
package org.springframework.social.partnercenter.serialization;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class JsonSerializationSettings {
	private Map deserializationFeatures;
	private Map serializationFeatures;
	private Map mapperFeatures;
	private Collection modules;

	private JsonSerializationSettings(Map deserializationFeatures,
									  Map serializationFeatures,
									  Map mapperFeatures,
									  Collection modules) {
		this.deserializationFeatures = deserializationFeatures;
		this.serializationFeatures = serializationFeatures;
		this.mapperFeatures = mapperFeatures;
		this.modules = modules;
	}

	public ObjectMapper createMapper(){
		final ObjectMapper mapper = new ObjectMapper();
		deserializationFeatures.keySet().forEach(key -> mapper.configure(key, deserializationFeatures.get(key)));
		serializationFeatures.keySet().forEach(key -> mapper.configure(key, serializationFeatures.get(key)));
		mapperFeatures.keySet().forEach(key -> mapper.configure(key, mapperFeatures.get(key)));
		modules.forEach(mapper::registerModule);
		return mapper;
	}

	public Map getDeserializationFeatures() {
		return deserializationFeatures;
	}

	public Map getSerializationFeatures() {
		return serializationFeatures;
	}

	public Map getMapperFeatures() {
		return mapperFeatures;
	}

	public static Builder builder(){
		return new Builder();
	}

	public static class Builder{
		private Map deserializationFeatures;
		private Map serializationFeatures;
		private Map mapperFeatures;
		private Collection modules;

		public Builder() {
			deserializationFeatures = new HashMap<>();
			serializationFeatures = new HashMap<>();
			mapperFeatures = new HashMap<>();
			modules = new ArrayList<>();
		}

		public Builder with(DeserializationFeature deserializationFeature, boolean activated){
			deserializationFeatures.put(deserializationFeature, activated);
			return this;
		}

		public Builder with(SerializationFeature serializationFeature, boolean activated){
			serializationFeatures.put(serializationFeature, activated);
			return this;
		}

		public Builder with(MapperFeature mapperFeature, boolean activated){
			mapperFeatures.put(mapperFeature, activated);
			return this;
		}

		public Builder with(Module module){
			this.modules.add(module);
			return this;
		}

		public JsonSerializationSettings build(){
			return new JsonSerializationSettings(deserializationFeatures, serializationFeatures, mapperFeatures, modules);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy