|
6 | 6 | import com.fasterxml.jackson.core.*;
|
7 | 7 |
|
8 | 8 | import com.fasterxml.jackson.databind.BeanProperty;
|
| 9 | +import com.fasterxml.jackson.databind.JsonMappingException; |
9 | 10 | import com.fasterxml.jackson.databind.JsonSerializer;
|
10 | 11 | import com.fasterxml.jackson.databind.SerializerProvider;
|
11 | 12 | import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
| 13 | +import com.fasterxml.jackson.databind.ser.ContextualSerializer; |
12 | 14 | import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
|
13 | 15 |
|
14 | 16 | import org.hibernate.engine.spi.Mapping;
|
|
27 | 29 | */
|
28 | 30 | public class HibernateProxySerializer
|
29 | 31 | extends JsonSerializer<HibernateProxy>
|
| 32 | + implements ContextualSerializer |
30 | 33 | {
|
31 | 34 | /**
|
32 | 35 | * Property that has proxy value to handle
|
@@ -66,6 +69,16 @@ public HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdent
|
66 | 69 | _property = null;
|
67 | 70 | }
|
68 | 71 |
|
| 72 | + public HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier, Mapping mapping, BeanProperty property) { |
| 73 | + _forceLazyLoading = forceLazyLoading; |
| 74 | + _serializeIdentifier = serializeIdentifier; |
| 75 | + _mapping = mapping; |
| 76 | + _dynamicSerializers = PropertySerializerMap.emptyForProperties(); |
| 77 | + _property = property; |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | + |
69 | 82 | /*
|
70 | 83 | /**********************************************************************
|
71 | 84 | /* JsonSerializer impl
|
@@ -165,4 +178,10 @@ protected Object findProxied(HibernateProxy proxy)
|
165 | 178 | }
|
166 | 179 | return init.getImplementation();
|
167 | 180 | }
|
| 181 | + |
| 182 | + @Override |
| 183 | + public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) |
| 184 | + throws JsonMappingException { |
| 185 | + return new HibernateProxySerializer(this._forceLazyLoading, this._serializeIdentifier, this._mapping, property); |
| 186 | + } |
168 | 187 | }
|
0 commit comments