18
18
import com .fasterxml .jackson .databind .jsontype .TypeSerializer ;
19
19
import com .fasterxml .jackson .databind .ser .ContextualSerializer ;
20
20
import com .fasterxml .jackson .databind .ser .impl .PropertySerializerMap ;
21
+ import com .fasterxml .jackson .databind .util .NameTransformer ;
21
22
22
23
import org .hibernate .engine .spi .Mapping ;
23
24
import org .hibernate .engine .spi .SessionFactoryImplementor ;
@@ -48,6 +49,7 @@ public class HibernateProxySerializer
48
49
protected final boolean _serializeIdentifier ;
49
50
protected final boolean _nullMissingEntities ;
50
51
protected final Mapping _mapping ;
52
+ protected final NameTransformer _unwrapper ;
51
53
52
54
/**
53
55
* For efficient serializer lookup, let's use this; most
@@ -63,36 +65,57 @@ public class HibernateProxySerializer
63
65
64
66
public HibernateProxySerializer (boolean forceLazyLoading )
65
67
{
66
- this (forceLazyLoading , false , false , null , null );
68
+ this (forceLazyLoading , false , false , null , null , null );
67
69
}
68
70
69
71
public HibernateProxySerializer (boolean forceLazyLoading , boolean serializeIdentifier ) {
70
- this (forceLazyLoading , serializeIdentifier , false , null , null );
72
+ this (forceLazyLoading , serializeIdentifier , false , null , null , null );
71
73
}
72
74
73
75
public HibernateProxySerializer (boolean forceLazyLoading , boolean serializeIdentifier , Mapping mapping ) {
74
- this (forceLazyLoading , serializeIdentifier , false , mapping , null );
76
+ this (forceLazyLoading , serializeIdentifier , false , mapping , null , null );
75
77
}
76
78
77
79
public HibernateProxySerializer (boolean forceLazyLoading , boolean serializeIdentifier , boolean nullMissingEntities , Mapping mapping ) {
78
- this (forceLazyLoading , serializeIdentifier , nullMissingEntities , mapping , null );
80
+ this (forceLazyLoading , serializeIdentifier , nullMissingEntities , mapping , null , null );
79
81
}
80
82
81
83
public HibernateProxySerializer (boolean forceLazyLoading , boolean serializeIdentifier , boolean nullMissingEntities , Mapping mapping ,
82
- BeanProperty property ) {
84
+ BeanProperty property ) {
85
+ this (forceLazyLoading , serializeIdentifier , nullMissingEntities , mapping , property , null );
86
+ }
87
+
88
+
89
+ protected HibernateProxySerializer (boolean forceLazyLoading , boolean serializeIdentifier , boolean nullMissingEntities , Mapping mapping ,
90
+ BeanProperty property , NameTransformer unwrapper ) {
83
91
_forceLazyLoading = forceLazyLoading ;
84
92
_serializeIdentifier = serializeIdentifier ;
85
93
_nullMissingEntities = nullMissingEntities ;
86
94
_mapping = mapping ;
87
95
_dynamicSerializers = PropertySerializerMap .emptyForProperties ();
88
96
_property = property ;
97
+ _unwrapper = unwrapper ;
89
98
}
90
99
91
100
@ Override
92
101
public JsonSerializer <?> createContextual (SerializerProvider prov , BeanProperty property ) {
93
102
return new HibernateProxySerializer (this ._forceLazyLoading , _serializeIdentifier , _nullMissingEntities ,
94
- _mapping , property );
95
- }
103
+ _mapping , property , _unwrapper );
104
+ }
105
+
106
+ @ Override
107
+ public JsonSerializer <HibernateProxy > unwrappingSerializer (
108
+ final NameTransformer unwrapper )
109
+ {
110
+ return new HibernateProxySerializer (_forceLazyLoading , _serializeIdentifier , _nullMissingEntities ,
111
+ _mapping , _property , unwrapper == null ? NameTransformer .NOP : unwrapper );
112
+ }
113
+
114
+ @ Override
115
+ public boolean isUnwrappingSerializer ()
116
+ {
117
+ return _unwrapper != null ;
118
+ }
96
119
97
120
/*
98
121
/**********************************************************************
@@ -175,6 +198,10 @@ protected JsonSerializer<Object> findSerializer(SerializerProvider provider, Obj
175
198
if (_dynamicSerializers != result .map ) {
176
199
_dynamicSerializers = result .map ;
177
200
}
201
+ if (_unwrapper != null )
202
+ {
203
+ return result .serializer .unwrappingSerializer (_unwrapper );
204
+ }
178
205
return result .serializer ;
179
206
}
180
207
0 commit comments