1
1
package com .fasterxml .jackson .datatype .hibernate4 ;
2
2
3
+ import java .io .IOException ;
4
+ import java .util .HashMap ;
5
+
3
6
import com .fasterxml .jackson .core .JsonGenerator ;
4
7
import com .fasterxml .jackson .core .JsonProcessingException ;
8
+
5
9
import com .fasterxml .jackson .databind .BeanProperty ;
6
10
import com .fasterxml .jackson .databind .JsonSerializer ;
7
11
import com .fasterxml .jackson .databind .SerializerProvider ;
8
12
import com .fasterxml .jackson .databind .jsontype .TypeSerializer ;
13
+ import com .fasterxml .jackson .databind .ser .ContextualSerializer ;
9
14
import com .fasterxml .jackson .databind .ser .impl .PropertySerializerMap ;
15
+
10
16
import org .hibernate .engine .spi .Mapping ;
11
17
import org .hibernate .engine .spi .SessionImplementor ;
12
18
import org .hibernate .proxy .HibernateProxy ;
13
19
import org .hibernate .proxy .LazyInitializer ;
14
20
15
- import java .io .IOException ;
16
- import java .util .HashMap ;
17
-
18
21
/**
19
22
* Serializer to use for values proxied using {@link org.hibernate.proxy.HibernateProxy}.
20
23
*<p>
26
29
*/
27
30
public class HibernateProxySerializer
28
31
extends JsonSerializer <HibernateProxy >
32
+ implements ContextualSerializer
29
33
{
30
34
/**
31
35
* Property that has proxy value to handle
@@ -50,21 +54,32 @@ public class HibernateProxySerializer
50
54
51
55
public HibernateProxySerializer (boolean forceLazyLoading )
52
56
{
53
- this (forceLazyLoading , false , null );
57
+ this (forceLazyLoading , false , null , null );
54
58
}
55
59
56
60
public HibernateProxySerializer (boolean forceLazyLoading , boolean serializeIdentifier ) {
57
- this (forceLazyLoading , serializeIdentifier , null );
61
+ this (forceLazyLoading , serializeIdentifier , null , null );
58
62
}
59
63
60
64
public HibernateProxySerializer (boolean forceLazyLoading , boolean serializeIdentifier , Mapping mapping ) {
65
+ this (forceLazyLoading , serializeIdentifier , mapping , null );
66
+ }
67
+
68
+ public HibernateProxySerializer (boolean forceLazyLoading , boolean serializeIdentifier , Mapping mapping ,
69
+ BeanProperty property ) {
61
70
_forceLazyLoading = forceLazyLoading ;
62
71
_serializeIdentifier = serializeIdentifier ;
63
72
_mapping = mapping ;
64
- _dynamicSerializers = PropertySerializerMap .emptyMap ();
65
- _property = null ;
73
+ _dynamicSerializers = PropertySerializerMap .emptyForProperties ();
74
+ _property = property ;
66
75
}
67
-
76
+
77
+ @ Override
78
+ public JsonSerializer <?> createContextual (SerializerProvider prov , BeanProperty property ) {
79
+ return new HibernateProxySerializer (this ._forceLazyLoading , _serializeIdentifier ,
80
+ _mapping , property );
81
+ }
82
+
68
83
/*
69
84
/**********************************************************************
70
85
/* JsonSerializer impl
0 commit comments