Skip to content

Commit abdf993

Browse files
committed
wip
1 parent 49ee2f3 commit abdf993

File tree

2 files changed

+65
-9
lines changed

2 files changed

+65
-9
lines changed

hibernate7/src/main/java/tools/jackson/datatype/hibernate7/PersistentCollectionSerializer.java

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import tools.jackson.databind.*;
1818
import tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
1919
import tools.jackson.databind.jsontype.TypeSerializer;
20+
import tools.jackson.databind.ser.std.StdContainerSerializer;
2021
import tools.jackson.databind.util.NameTransformer;
2122

2223
import jakarta.persistence.ElementCollection;
@@ -33,7 +34,7 @@
3334
* and <code>Map</code> types (unlike in JDK).
3435
*/
3536
public class PersistentCollectionSerializer
36-
extends ValueSerializer<Object>
37+
extends StdContainerSerializer<Object>
3738
{
3839
private static final long serialVersionUID = 1L;
3940

@@ -93,6 +94,20 @@ protected PersistentCollectionSerializer _withSerializer(ValueSerializer<?> ser)
9394
return new PersistentCollectionSerializer(this, ser);
9495
}
9596

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+
96111
/*
97112
/**********************************************************************
98113
/* Contextualization
@@ -161,6 +176,43 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t
161176
_serializer.acceptJsonFormatVisitor(visitor, typeHint);
162177
}
163178

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+
164216
/*
165217
/**********************************************************************
166218
/* ValueSerializer, actual serialization
@@ -217,6 +269,13 @@ public void serializeWithType(Object value, JsonGenerator g, SerializationContex
217269
/**********************************************************************
218270
*/
219271

272+
protected StdContainerSerializer<?> _containerSerializer() {
273+
if (_serializer instanceof StdContainerSerializer) {
274+
return (StdContainerSerializer<?>) _serializer;
275+
}
276+
return null;
277+
}
278+
220279
protected Object findLazyValue(PersistentCollection coll) {
221280
// If lazy-loaded, not yet loaded, may serialize as null?
222281
if (!Hibernate7Module.Feature.FORCE_LAZY_LOADING.enabledIn(_features) && !coll.wasInitialized()) {

pom.xml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
</dependencyManagement>
7878

7979
<dependencies>
80+
<dependency>
81+
<groupId>com.fasterxml.jackson.core</groupId>
82+
<artifactId>jackson-annotations</artifactId>
83+
</dependency>
8084
<dependency>
8185
<groupId>tools.jackson.core</groupId>
8286
<artifactId>jackson-core</artifactId>
@@ -102,13 +106,6 @@
102106
<artifactId>assertj-core</artifactId>
103107
<scope>test</scope>
104108
</dependency>
105-
106-
<!-- But there are also some well-known test dependencies we may as well add directly -->
107-
<dependency>
108-
<groupId>com.fasterxml.jackson.core</groupId>
109-
<artifactId>jackson-annotations</artifactId>
110-
<scope>test</scope>
111-
</dependency>
112109
</dependencies>
113110

114111
<!-- Need to include snapshot reference to find snapshot of parent -->
@@ -143,7 +140,7 @@
143140
<artifactId>maven-surefire-plugin</artifactId>
144141
<configuration>
145142
<excludes>
146-
<exclude>com/fasterxml/jackson/**/failing/*.java</exclude>
143+
<exclude>tools/jackson/**/failing/*.java</exclude>
147144
</excludes>
148145
</configuration>
149146
</plugin>

0 commit comments

Comments
 (0)