| 
17 | 17 | import tools.jackson.databind.*;  | 
18 | 18 | import tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;  | 
19 | 19 | import tools.jackson.databind.jsontype.TypeSerializer;  | 
 | 20 | +import tools.jackson.databind.ser.std.StdContainerSerializer;  | 
20 | 21 | import tools.jackson.databind.util.NameTransformer;  | 
21 | 22 | 
 
  | 
22 | 23 | import jakarta.persistence.ElementCollection;  | 
 | 
33 | 34 |  * and <code>Map</code> types (unlike in JDK).  | 
34 | 35 |  */  | 
35 | 36 | public class PersistentCollectionSerializer  | 
36 |  | -    extends ValueSerializer<Object>  | 
 | 37 | +    extends StdContainerSerializer<Object>  | 
37 | 38 | {  | 
38 | 39 |     private static final long serialVersionUID = 1L;  | 
39 | 40 | 
 
  | 
@@ -93,6 +94,20 @@ protected PersistentCollectionSerializer _withSerializer(ValueSerializer<?> ser)  | 
93 | 94 |         return new PersistentCollectionSerializer(this, ser);  | 
94 | 95 |     }  | 
95 | 96 | 
 
  | 
 | 97 | +    // from `ContainerSerializer`  | 
 | 98 | +    @Override  | 
 | 99 | +    protected StdContainerSerializer<?> _withValueTypeSerializer(TypeSerializer vts)  | 
 | 100 | +    {  | 
 | 101 | +        StdContainerSerializer<?> ser0 = _containerSerializer();  | 
 | 102 | +        if (ser0 != null) {  | 
 | 103 | +            return _withSerializer(ser0.withValueTypeSerializer(vts));  | 
 | 104 | +        }  | 
 | 105 | +        // 03-Jan-2016, tatu: Not sure what to do here; most likely can not make it work without  | 
 | 106 | +        //    knowing how to pass various calls... so in a way, should limit to only accepting  | 
 | 107 | +        //    ContainerSerializers as delegates.  | 
 | 108 | +        return this;  | 
 | 109 | +    }  | 
 | 110 | + | 
96 | 111 |     /*  | 
97 | 112 |     /**********************************************************************  | 
98 | 113 |     /* Contextualization  | 
@@ -161,6 +176,43 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t  | 
161 | 176 |         _serializer.acceptJsonFormatVisitor(visitor, typeHint);  | 
162 | 177 |     }  | 
163 | 178 | 
 
  | 
 | 179 | +    /*  | 
 | 180 | +    /**********************************************************************  | 
 | 181 | +    /* ContainerSerializer methods  | 
 | 182 | +    /**********************************************************************  | 
 | 183 | +     */  | 
 | 184 | + | 
 | 185 | +    @Override  | 
 | 186 | +    public JavaType getContentType() {  | 
 | 187 | +        StdContainerSerializer<?> ser = _containerSerializer();  | 
 | 188 | +        if (ser != null) {  | 
 | 189 | +            return ser.getContentType();  | 
 | 190 | +        }  | 
 | 191 | +        return _originalType.getContentType();  | 
 | 192 | +    }  | 
 | 193 | + | 
 | 194 | +    @Override  | 
 | 195 | +    public ValueSerializer<?> getContentSerializer() {  | 
 | 196 | +        StdContainerSerializer<?> ser = _containerSerializer();  | 
 | 197 | +        if (ser != null) {  | 
 | 198 | +            return ser.getContentSerializer();  | 
 | 199 | +        }  | 
 | 200 | +        // no idea, alas  | 
 | 201 | +        return null;  | 
 | 202 | +    }  | 
 | 203 | + | 
 | 204 | +    @Override  | 
 | 205 | +    public boolean hasSingleElement(Object value) {  | 
 | 206 | +        if (value instanceof Collection<?>) {  | 
 | 207 | +            return ((Collection<?>) value).size() == 1;  | 
 | 208 | +        }  | 
 | 209 | +        if (value instanceof Map<?,?>) {  | 
 | 210 | +            return ((Map<?,?>) value).size() == 1;  | 
 | 211 | +        }  | 
 | 212 | +        return false;  | 
 | 213 | +    }  | 
 | 214 | + | 
 | 215 | + | 
164 | 216 |     /*  | 
165 | 217 |     /**********************************************************************  | 
166 | 218 |     /* ValueSerializer, actual serialization  | 
@@ -217,6 +269,13 @@ public void serializeWithType(Object value, JsonGenerator g, SerializationContex  | 
217 | 269 |     /**********************************************************************  | 
218 | 270 |      */  | 
219 | 271 | 
 
  | 
 | 272 | +    protected StdContainerSerializer<?> _containerSerializer() {  | 
 | 273 | +        if (_serializer instanceof StdContainerSerializer) {  | 
 | 274 | +            return (StdContainerSerializer<?>) _serializer;  | 
 | 275 | +        }  | 
 | 276 | +        return null;  | 
 | 277 | +    }  | 
 | 278 | + | 
220 | 279 |     protected Object findLazyValue(PersistentCollection coll) {  | 
221 | 280 |         // If lazy-loaded, not yet loaded, may serialize as null?  | 
222 | 281 |         if (!Hibernate7Module.Feature.FORCE_LAZY_LOADING.enabledIn(_features) && !coll.wasInitialized()) {  | 
 | 
0 commit comments