package com.github.pepe79.jats.json;

import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.introspect.BasicBeanDescription;
import org.codehaus.jackson.map.ser.BeanPropertyWriter;
import org.codehaus.jackson.map.ser.BeanSerializerModifier;

import com.github.pepe79.jats.json.idextractor.IdExtractor;

public class JatsBeanSerializerModifier extends BeanSerializerModifier
{

	private Set<String> propertyWhiteList;

	private IdExtractor idExtractor;

	public JatsBeanSerializerModifier(IdExtractor idExtractor,
			Set<String> propertyWhiteList)
	{
		this.propertyWhiteList = propertyWhiteList;
		this.idExtractor = idExtractor;
	}

	@Override
	public List<BeanPropertyWriter> changeProperties(
			SerializationConfig config, BasicBeanDescription beanDesc,
			List<BeanPropertyWriter> beanProperties)
	{
		{
			Iterator<BeanPropertyWriter> it = beanProperties.iterator();
			while (it.hasNext())
			{
				BeanPropertyWriter bpw = it.next();

				if (propertyWhiteList != null
						&& !propertyWhiteList.contains(bpw.getName()))
				{
					it.remove();
				}
			}
		}

		return beanProperties;
	}

	@Override
	public JsonSerializer<?> modifySerializer(SerializationConfig config,
			BasicBeanDescription beanDesc, JsonSerializer<?> serializer)
	{
		return new JatsJsonSerializer<>(serializer, idExtractor);
	}

}

@@ -656,20 +656,17 @@
 tractor,
-%0A%09%09%09
+ 
 Set%3CStri
@@ -836,20 +836,16 @@
 perties(
-%0A%09%09%09
 Serializ
@@ -1117,15 +1117,9 @@
 null
-%0A%09%09%09%09%09%09
+ 
 && !
@@ -1226,24 +1226,56 @@
 erties;%0A%09%7D%0A%0A
+%09@SuppressWarnings(%22unchecked%22)%0A
 %09@Override%0A%09
@@ -1296,17 +1296,22 @@
 ializer%3C
-?
+Object
 %3E modify
@@ -1348,20 +1348,17 @@
  config,
-%0A%09%09%09
+ 
 BasicBea
@@ -1379,17 +1379,20 @@
 eanDesc,
- 
+%0A%09%09%09
 JsonSeri
@@ -1452,10 +1452,41 @@
 zer%3C
-%3E(
+Object%3E((JsonSerializer%3CObject%3E) 
 seri

remove java 7 dependency (diamond operator)