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:
committed by
Mahmoud Ben Hassine
parent
15d24b370f
commit
a0bcd7ce45
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user