|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
20 | 20 | import java.io.InputStream;
|
21 | 21 | import java.io.ObjectInputStream;
|
22 | 22 |
|
| 23 | +import org.springframework.core.ConfigurableObjectInputStream; |
23 | 24 | import org.springframework.core.NestedIOException;
|
24 | 25 |
|
25 | 26 | /**
|
26 |
| - * Deserializer that reads an input stream using Java Serialization. |
| 27 | + * A default {@link Deserializer} implementation that reads an input stream |
| 28 | + * using Java serialization. |
27 | 29 | *
|
28 | 30 | * @author Gary Russell
|
29 | 31 | * @author Mark Fisher
|
| 32 | + * @author Juergen Hoeller |
30 | 33 | * @since 3.0.5
|
| 34 | + * @see ObjectInputStream |
31 | 35 | */
|
32 | 36 | public class DefaultDeserializer implements Deserializer<Object> {
|
33 | 37 |
|
| 38 | + private final ClassLoader classLoader; |
| 39 | + |
| 40 | + |
| 41 | + /** |
| 42 | + * Create a {@code DefaultDeserializer} with default {@link ObjectInputStream} |
| 43 | + * configuration, using the "latest user-defined ClassLoader". |
| 44 | + */ |
| 45 | + public DefaultDeserializer() { |
| 46 | + this.classLoader = null; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Create a {@code DefaultDeserializer} for using an {@link ObjectInputStream} |
| 51 | + * with the given {@code ClassLoader}. |
| 52 | + * @since 4.2.1 |
| 53 | + * @see ConfigurableObjectInputStream#ConfigurableObjectInputStream(InputStream, ClassLoader) |
| 54 | + */ |
| 55 | + public DefaultDeserializer(ClassLoader classLoader) { |
| 56 | + this.classLoader = classLoader; |
| 57 | + } |
| 58 | + |
| 59 | + |
34 | 60 | /**
|
35 | 61 | * Reads the input stream and deserializes into an object.
|
| 62 | + * @see ObjectInputStream#readObject() |
36 | 63 | */
|
37 | 64 | @Override
|
38 | 65 | public Object deserialize(InputStream inputStream) throws IOException {
|
39 |
| - ObjectInputStream objectInputStream = new ObjectInputStream(inputStream); |
| 66 | + ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream, this.classLoader); |
40 | 67 | try {
|
41 | 68 | return objectInputStream.readObject();
|
42 | 69 | }
|
|
0 commit comments