Add ability to amend trusted classes in Jackson2ExecutionContextStringSerializer

This commit adds the ability to specify additional trusted
classes without having to provide a custom object mapper.

Issue #3765
This commit is contained in:
Mahmoud Ben Hassine
2020-10-06 15:10:41 +02:00
committed by Mahmoud Ben Hassine
parent 15d24b370f
commit a0bcd7ce45
2 changed files with 53 additions and 11 deletions

View File

@@ -20,9 +20,11 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -33,6 +35,7 @@ import static org.junit.Assert.fail;
/**
* @author Marten Deinum
* @author Michael Minella
* @author Mahmoud Ben Hassine
*/
public class Jackson2ExecutionContextStringSerializerTests extends AbstractExecutionContextSerializerTests {
@@ -73,6 +76,25 @@ public class Jackson2ExecutionContextStringSerializerTests extends AbstractExecu
}
}
@Test
public void testAdditionalTrustedClass() throws IOException {
// given
Jackson2ExecutionContextStringSerializer serializer =
new Jackson2ExecutionContextStringSerializer("java.util.Locale");
Map<String, Object> context = new HashMap<>(1);
context.put("locale", Locale.getDefault());
// when
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
serializer.serialize(context, outputStream);
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
Map<String, Object> deserializedContext = serializer.deserialize(inputStream);
// then
Locale locale = (Locale) deserializedContext.get("locale");
Assert.assertNotNull(locale);
}
@Override
protected ExecutionContextSerializer getSerializer() {
return this.serializer;