11package com .fasterxml .jackson .datatype .hibernate4 ;
22
3+ import java .io .IOException ;
4+ import java .util .HashMap ;
5+
36import com .fasterxml .jackson .core .JsonGenerator ;
47import com .fasterxml .jackson .core .JsonProcessingException ;
8+
59import com .fasterxml .jackson .databind .BeanProperty ;
610import com .fasterxml .jackson .databind .JsonSerializer ;
711import com .fasterxml .jackson .databind .SerializerProvider ;
812import com .fasterxml .jackson .databind .jsontype .TypeSerializer ;
13+ import com .fasterxml .jackson .databind .ser .ContextualSerializer ;
914import com .fasterxml .jackson .databind .ser .impl .PropertySerializerMap ;
15+
1016import org .hibernate .engine .spi .Mapping ;
1117import org .hibernate .engine .spi .SessionImplementor ;
1218import org .hibernate .proxy .HibernateProxy ;
1319import org .hibernate .proxy .LazyInitializer ;
1420
15- import java .io .IOException ;
16- import java .util .HashMap ;
17-
1821/**
1922 * Serializer to use for values proxied using {@link org.hibernate.proxy.HibernateProxy}.
2023 *<p>
2629 */
2730public class HibernateProxySerializer
2831 extends JsonSerializer <HibernateProxy >
32+ implements ContextualSerializer
2933{
3034 /**
3135 * Property that has proxy value to handle
@@ -50,21 +54,32 @@ public class HibernateProxySerializer
5054
5155 public HibernateProxySerializer (boolean forceLazyLoading )
5256 {
53- this (forceLazyLoading , false , null );
57+ this (forceLazyLoading , false , null , null );
5458 }
5559
5660 public HibernateProxySerializer (boolean forceLazyLoading , boolean serializeIdentifier ) {
57- this (forceLazyLoading , serializeIdentifier , null );
61+ this (forceLazyLoading , serializeIdentifier , null , null );
5862 }
5963
6064 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 ) {
6170 _forceLazyLoading = forceLazyLoading ;
6271 _serializeIdentifier = serializeIdentifier ;
6372 _mapping = mapping ;
64- _dynamicSerializers = PropertySerializerMap .emptyMap ();
65- _property = null ;
73+ _dynamicSerializers = PropertySerializerMap .emptyForProperties ();
74+ _property = property ;
6675 }
67-
76+
77+ @ Override
78+ public JsonSerializer <?> createContextual (SerializerProvider prov , BeanProperty property ) {
79+ return new HibernateProxySerializer (this ._forceLazyLoading , _serializeIdentifier ,
80+ _mapping , property );
81+ }
82+
6883 /*
6984 /**********************************************************************
7085 /* JsonSerializer impl
0 commit comments