Skip to content

Commit 046bf7a

Browse files
committed
Clone non serializable objects in JSON
See vladmihalcea/hypersistence-utils#834
1 parent 422aa85 commit 046bf7a

4 files changed

Lines changed: 107 additions & 59 deletions

File tree

server/dependency.tree

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ Downloading from central: https://repo.maven.apache.org/maven2/io/github/git-com
99
Downloading from central: https://repo.maven.apache.org/maven2/org/flywaydb/maven-metadata.xml
1010
Downloading from central: https://repo.maven.apache.org/maven2/org/cyclonedx/maven-metadata.xml
1111
Downloading from central: https://repo.maven.apache.org/maven2/org/jooq/maven-metadata.xml
12-
Progress (1): 398 BProgress (2): 398 B | 243 BProgress (3): 398 B | 243 B | 255 BProgress (4): 398 B | 243 B | 255 B | 234 B Downloaded from central: https://repo.maven.apache.org/maven2/org/jooq/maven-metadata.xml (398 B at 1.2 kB/s)
13-
Downloaded from central: https://repo.maven.apache.org/maven2/io/github/git-commit-id/maven-metadata.xml (255 B at 787 B/s)
14-
Downloaded from central: https://repo.maven.apache.org/maven2/org/flywaydb/maven-metadata.xml (234 B at 720 B/s)
15-
Downloaded from central: https://repo.maven.apache.org/maven2/org/cyclonedx/maven-metadata.xml (243 B at 747 B/s)
16-
Downloading from central: https://repo.maven.apache.org/maven2/org/graalvm/buildtools/maven-metadata.xml
12+
Progress (1): 255 BProgress (2): 255 B | 234 BProgress (3): 255 B | 234 B | 243 BProgress (4): 255 B | 234 B | 243 B | 398 B Downloaded from central: https://repo.maven.apache.org/maven2/org/cyclonedx/maven-metadata.xml (243 B at 642 B/s)
13+
Downloaded from central: https://repo.maven.apache.org/maven2/org/flywaydb/maven-metadata.xml (234 B at 619 B/s)
14+
Downloaded from central: https://repo.maven.apache.org/maven2/org/jooq/maven-metadata.xml (398 B at 1.1 kB/s)
15+
Downloaded from central: https://repo.maven.apache.org/maven2/io/github/git-commit-id/maven-metadata.xml (255 B at 674 B/s)
1716
Downloading from central: https://repo.maven.apache.org/maven2/org/liquibase/maven-metadata.xml
1817
Downloading from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/maven-metadata.xml
18+
Downloading from central: https://repo.maven.apache.org/maven2/org/graalvm/buildtools/maven-metadata.xml
1919
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/maven-metadata.xml
20-
Progress (1): 375 BProgress (2): 375 B | 249 BProgress (3): 375 B | 249 B | 242 B Downloaded from central: https://repo.maven.apache.org/maven2/org/graalvm/buildtools/maven-metadata.xml (242 B at 11 kB/s)
21-
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/maven-metadata.xml (249 B at 11 kB/s)
22-
Downloaded from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/maven-metadata.xml (375 B at 16 kB/s)
23-
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
20+
Progress (1): 249 BProgress (2): 249 B | 242 B Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/maven-metadata.xml (249 B at 7.8 kB/s)
21+
Downloaded from central: https://repo.maven.apache.org/maven2/org/graalvm/buildtools/maven-metadata.xml (242 B at 7.3 kB/s)
2422
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
25-
Progress (1): 243 B Downloaded from central: https://repo.maven.apache.org/maven2/org/liquibase/maven-metadata.xml (243 B at 9.3 kB/s)
26-
Progress (1): 4.6 kBProgress (1): 9.8 kBProgress (1): 14 kB Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (14 kB at 621 kB/s)
27-
Progress (1): 3.7 kBProgress (1): 7.5 kBProgress (1): 13 kB Progress (1): 19 kBProgress (1): 20 kB Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (20 kB at 724 kB/s)
23+
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
24+
Progress (1): 375 BProgress (2): 375 B | 243 B Downloaded from central: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/maven-metadata.xml (375 B at 10 kB/s)
25+
Downloaded from central: https://repo.maven.apache.org/maven2/org/liquibase/maven-metadata.xml (243 B at 6.6 kB/s)
26+
Progress (1): 3.1 kBProgress (1): 7.8 kBProgress (1): 12 kB Progress (1): 17 kBProgress (1): 20 kBProgress (1): 21 kBProgress (2): 21 kB | 4.6 kBProgress (2): 21 kB | 9.8 kBProgress (2): 21 kB | 14 kB Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (14 kB at 366 kB/s)
27+
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (21 kB at 290 kB/s)
2828
[INFO]
2929
[INFO] -----------------------< org.openconext:access >------------------------
3030
[INFO] Building access 0.0.1-SNAPSHOT [1/3]
@@ -39,7 +39,7 @@ Progress (1): 3.7 kBProgress (1): 7.5 kBProgress (1): 13 kB Progress (1): 19
3939
[INFO] from server/pom.xml
4040
[INFO] --------------------------------[ jar ]---------------------------------
4141
Downloading from central: https://repo.maven.apache.org/maven2/org/jacoco/maven-metadata.xml
42-
Progress (1): 237 B Downloaded from central: https://repo.maven.apache.org/maven2/org/jacoco/maven-metadata.xml (237 B at 8.2 kB/s)
42+
Progress (1): 237 B Downloaded from central: https://repo.maven.apache.org/maven2/org/jacoco/maven-metadata.xml (237 B at 7.2 kB/s)
4343
[INFO]
4444
[INFO] --- dependency:3.8.1:tree (default-cli) @ access-server ---
4545
[INFO] org.openconext:access-server:jar:0.0.1-SNAPSHOT
@@ -98,38 +98,38 @@ Progress (1): 237 B Downloaded from central: https://repo.ma
9898
[INFO] | +- org.springframework:spring-web:jar:6.2.10:compile
9999
[INFO] | \- org.springframework:spring-webmvc:jar:6.2.10:compile
100100
[INFO] +- org.springframework.boot:spring-boot-configuration-processor:jar:3.5.5:compile (optional)
101-
[INFO] +- software.amazon.awssdk:s3:jar:2.41.13:compile
102-
[INFO] | +- software.amazon.awssdk:aws-xml-protocol:jar:2.41.13:compile
103-
[INFO] | | \- software.amazon.awssdk:aws-query-protocol:jar:2.41.13:compile
104-
[INFO] | +- software.amazon.awssdk:protocol-core:jar:2.41.13:compile
105-
[INFO] | +- software.amazon.awssdk:arns:jar:2.41.13:compile
106-
[INFO] | +- software.amazon.awssdk:profiles:jar:2.41.13:compile
107-
[INFO] | +- software.amazon.awssdk:crt-core:jar:2.41.13:compile
108-
[INFO] | +- software.amazon.awssdk:http-auth:jar:2.41.13:compile
109-
[INFO] | +- software.amazon.awssdk:identity-spi:jar:2.41.13:compile
110-
[INFO] | +- software.amazon.awssdk:http-auth-spi:jar:2.41.13:compile
101+
[INFO] +- software.amazon.awssdk:s3:jar:2.41.15:compile
102+
[INFO] | +- software.amazon.awssdk:aws-xml-protocol:jar:2.41.15:compile
103+
[INFO] | | \- software.amazon.awssdk:aws-query-protocol:jar:2.41.15:compile
104+
[INFO] | +- software.amazon.awssdk:protocol-core:jar:2.41.15:compile
105+
[INFO] | +- software.amazon.awssdk:arns:jar:2.41.15:compile
106+
[INFO] | +- software.amazon.awssdk:profiles:jar:2.41.15:compile
107+
[INFO] | +- software.amazon.awssdk:crt-core:jar:2.41.15:compile
108+
[INFO] | +- software.amazon.awssdk:http-auth:jar:2.41.15:compile
109+
[INFO] | +- software.amazon.awssdk:identity-spi:jar:2.41.15:compile
110+
[INFO] | +- software.amazon.awssdk:http-auth-spi:jar:2.41.15:compile
111111
[INFO] | | \- org.reactivestreams:reactive-streams:jar:1.0.4:compile
112-
[INFO] | +- software.amazon.awssdk:http-auth-aws:jar:2.41.13:compile
113-
[INFO] | +- software.amazon.awssdk:checksums:jar:2.41.13:compile
114-
[INFO] | +- software.amazon.awssdk:checksums-spi:jar:2.41.13:compile
115-
[INFO] | +- software.amazon.awssdk:retries-spi:jar:2.41.13:compile
116-
[INFO] | +- software.amazon.awssdk:sdk-core:jar:2.41.13:compile
117-
[INFO] | | \- software.amazon.awssdk:retries:jar:2.41.13:compile
118-
[INFO] | +- software.amazon.awssdk:auth:jar:2.41.13:compile
119-
[INFO] | | +- software.amazon.awssdk:http-auth-aws-eventstream:jar:2.41.13:compile
112+
[INFO] | +- software.amazon.awssdk:http-auth-aws:jar:2.41.15:compile
113+
[INFO] | +- software.amazon.awssdk:checksums:jar:2.41.15:compile
114+
[INFO] | +- software.amazon.awssdk:checksums-spi:jar:2.41.15:compile
115+
[INFO] | +- software.amazon.awssdk:retries-spi:jar:2.41.15:compile
116+
[INFO] | +- software.amazon.awssdk:sdk-core:jar:2.41.15:compile
117+
[INFO] | | \- software.amazon.awssdk:retries:jar:2.41.15:compile
118+
[INFO] | +- software.amazon.awssdk:auth:jar:2.41.15:compile
119+
[INFO] | | +- software.amazon.awssdk:http-auth-aws-eventstream:jar:2.41.15:compile
120120
[INFO] | | \- software.amazon.eventstream:eventstream:jar:1.0.1:compile
121-
[INFO] | +- software.amazon.awssdk:http-client-spi:jar:2.41.13:compile
122-
[INFO] | +- software.amazon.awssdk:regions:jar:2.41.13:compile
123-
[INFO] | +- software.amazon.awssdk:annotations:jar:2.41.13:compile
124-
[INFO] | +- software.amazon.awssdk:utils:jar:2.41.13:compile
125-
[INFO] | +- software.amazon.awssdk:aws-core:jar:2.41.13:compile
126-
[INFO] | | \- software.amazon.awssdk:utils-lite:jar:2.41.13:compile
127-
[INFO] | +- software.amazon.awssdk:metrics-spi:jar:2.41.13:compile
128-
[INFO] | +- software.amazon.awssdk:json-utils:jar:2.41.13:compile
129-
[INFO] | | \- software.amazon.awssdk:third-party-jackson-core:jar:2.41.13:compile
130-
[INFO] | +- software.amazon.awssdk:endpoints-spi:jar:2.41.13:compile
131-
[INFO] | +- software.amazon.awssdk:apache-client:jar:2.41.13:runtime
132-
[INFO] | \- software.amazon.awssdk:netty-nio-client:jar:2.41.13:runtime
121+
[INFO] | +- software.amazon.awssdk:http-client-spi:jar:2.41.15:compile
122+
[INFO] | +- software.amazon.awssdk:regions:jar:2.41.15:compile
123+
[INFO] | +- software.amazon.awssdk:annotations:jar:2.41.15:compile
124+
[INFO] | +- software.amazon.awssdk:utils:jar:2.41.15:compile
125+
[INFO] | +- software.amazon.awssdk:aws-core:jar:2.41.15:compile
126+
[INFO] | | \- software.amazon.awssdk:utils-lite:jar:2.41.15:compile
127+
[INFO] | +- software.amazon.awssdk:metrics-spi:jar:2.41.15:compile
128+
[INFO] | +- software.amazon.awssdk:json-utils:jar:2.41.15:compile
129+
[INFO] | | \- software.amazon.awssdk:third-party-jackson-core:jar:2.41.15:compile
130+
[INFO] | +- software.amazon.awssdk:endpoints-spi:jar:2.41.15:compile
131+
[INFO] | +- software.amazon.awssdk:apache-client:jar:2.41.15:runtime
132+
[INFO] | \- software.amazon.awssdk:netty-nio-client:jar:2.41.15:runtime
133133
[INFO] | +- io.netty:netty-codec-http:jar:4.1.124.Final:runtime
134134
[INFO] | +- io.netty:netty-codec-http2:jar:4.1.124.Final:runtime
135135
[INFO] | +- io.netty:netty-codec:jar:4.1.124.Final:runtime
@@ -205,8 +205,8 @@ Progress (1): 237 B Downloaded from central: https://repo.ma
205205
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.19.2:compile
206206
[INFO] | \- com.fasterxml.jackson.core:jackson-databind:jar:2.19.2:compile
207207
[INFO] | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.19.2:compile
208-
[INFO] +- org.flywaydb:flyway-core:jar:11.20.2:compile
209-
[INFO] +- org.flywaydb:flyway-mysql:jar:11.20.2:compile
208+
[INFO] +- org.flywaydb:flyway-core:jar:11.20.3:compile
209+
[INFO] +- org.flywaydb:flyway-mysql:jar:11.20.3:compile
210210
[INFO] +- org.mariadb.jdbc:mariadb-java-client:jar:3.5.7:compile
211211
[INFO] +- com.github.spullara.mustache.java:compiler:jar:0.9.14:compile
212212
[INFO] +- commons-codec:commons-codec:jar:1.20.0:compile
@@ -246,10 +246,10 @@ Progress (1): 237 B Downloaded from central: https://repo.ma
246246
[INFO] +- io.rest-assured:rest-assured-common:jar:6.0.0:test
247247
[INFO] | \- org.apache.commons:commons-lang3:jar:3.17.0:compile
248248
[INFO] +- io.rest-assured:xml-path:jar:6.0.0:test
249-
[INFO] +- io.hypersistence:hypersistence-utils-hibernate-63:jar:3.14.1:compile
249+
[INFO] +- io.hypersistence:hypersistence-utils-hibernate-63:jar:3.15.1:compile
250250
[INFO] | \- io.hypersistence:hypersistence-tsid:jar:2.1.4:compile
251251
[INFO] +- net.coobird:thumbnailator:jar:0.4.21:compile
252-
[INFO] +- org.wiremock:wiremock-standalone:jar:4.0.0-beta.25:test
252+
[INFO] +- org.wiremock:wiremock-standalone:jar:4.0.0-beta.27:test
253253
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-hibernate6:jar:2.21.0:compile
254254
[INFO] | \- jakarta.transaction:jakarta.transaction-api:jar:2.0.1:compile
255255
[INFO] +- com.icegreen:greenmail-junit5:jar:2.1.8:test
@@ -266,14 +266,14 @@ Progress (1): 237 B Downloaded from central: https://repo.ma
266266
[INFO] | \- com.sun.mail:jakarta.mail:jar:1.6.7:test
267267
[INFO] | \- com.sun.activation:jakarta.activation:jar:1.2.1:test
268268
[INFO] +- org.awaitility:awaitility:jar:4.3.0:test
269-
[INFO] +- org.springdoc:springdoc-openapi-starter-webmvc-ui:jar:2.8.14:compile
270-
[INFO] | +- org.springdoc:springdoc-openapi-starter-webmvc-api:jar:2.8.14:compile
271-
[INFO] | | \- org.springdoc:springdoc-openapi-starter-common:jar:2.8.14:compile
272-
[INFO] | | \- io.swagger.core.v3:swagger-core-jakarta:jar:2.2.38:compile
273-
[INFO] | | +- io.swagger.core.v3:swagger-annotations-jakarta:jar:2.2.38:compile
274-
[INFO] | | +- io.swagger.core.v3:swagger-models-jakarta:jar:2.2.38:compile
269+
[INFO] +- org.springdoc:springdoc-openapi-starter-webmvc-ui:jar:2.8.15:compile
270+
[INFO] | +- org.springdoc:springdoc-openapi-starter-webmvc-api:jar:2.8.15:compile
271+
[INFO] | | \- org.springdoc:springdoc-openapi-starter-common:jar:2.8.15:compile
272+
[INFO] | | \- io.swagger.core.v3:swagger-core-jakarta:jar:2.2.41:compile
273+
[INFO] | | +- io.swagger.core.v3:swagger-annotations-jakarta:jar:2.2.41:compile
274+
[INFO] | | +- io.swagger.core.v3:swagger-models-jakarta:jar:2.2.41:compile
275275
[INFO] | | \- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.19.2:compile
276-
[INFO] | +- org.webjars:swagger-ui:jar:5.30.1:compile
276+
[INFO] | +- org.webjars:swagger-ui:jar:5.31.0:compile
277277
[INFO] | \- org.webjars:webjars-locator-lite:jar:1.1.0:compile
278278
[INFO] | \- org.jspecify:jspecify:jar:1.0.0:compile
279279
[INFO] +- org.bouncycastle:bcprov-jdk18on:jar:1.83:compile
@@ -291,12 +291,12 @@ Progress (1): 237 B Downloaded from central: https://repo.ma
291291
[INFO] ------------------------------------------------------------------------
292292
[INFO] Reactor Summary for access 0.0.1-SNAPSHOT:
293293
[INFO]
294-
[INFO] access ............................................. SUCCESS [ 0.733 s]
295-
[INFO] access-server ...................................... SUCCESS [ 0.690 s]
296-
[INFO] client ............................................. SUCCESS [ 0.011 s]
294+
[INFO] access ............................................. SUCCESS [ 0.747 s]
295+
[INFO] access-server ...................................... SUCCESS [ 0.673 s]
296+
[INFO] client ............................................. SUCCESS [ 0.009 s]
297297
[INFO] ------------------------------------------------------------------------
298298
[INFO] BUILD SUCCESS
299299
[INFO] ------------------------------------------------------------------------
300-
[INFO] Total time: 2.373 s
301-
[INFO] Finished at: 2026-01-26T10:01:35+01:00
300+
[INFO] Total time: 2.442 s
301+
[INFO] Finished at: 2026-02-01T09:44:59+01:00
302302
[INFO] ------------------------------------------------------------------------
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package access.json;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import io.hypersistence.utils.hibernate.type.util.JsonSerializer;
5+
6+
public class CloningJsonSerializer implements JsonSerializer {
7+
8+
private final ObjectMapper objectMapper;
9+
10+
public CloningJsonSerializer(ObjectMapper objectMapper) {
11+
this.objectMapper = objectMapper;
12+
}
13+
14+
@Override
15+
@SuppressWarnings("unchecked")
16+
public <T> T clone(T value) {
17+
if (value == null) {
18+
return null;
19+
}
20+
if (value instanceof String) {
21+
return value;
22+
}
23+
24+
try {
25+
// Serialize to JSON string and deserialize back to clone
26+
String json = objectMapper.writeValueAsString(value);
27+
return (T) objectMapper.readValue(json, value.getClass());
28+
} catch (Exception e) {
29+
throw new IllegalArgumentException("Cannot clone object: " + value.getClass(), e);
30+
}
31+
}
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package access.json;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import io.hypersistence.utils.hibernate.type.util.JsonSerializer;
5+
import io.hypersistence.utils.hibernate.type.util.JsonSerializerSupplier;
6+
7+
public class CloningJsonSerializerSupplier implements JsonSerializerSupplier {
8+
9+
private final ObjectMapper objectMapper = new ObjectMapper();
10+
11+
@Override
12+
public JsonSerializer get() {
13+
return new CloningJsonSerializer(objectMapper);
14+
}
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hypersistence.utils.json.serializer=access.json.CloningJsonSerializerSupplier

0 commit comments

Comments
 (0)