You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/03/01 07:48:49 UTC
[isis] 01/01: ISIS-2554: TypeIdentifier: serialization support
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 47f7c7050f398d8e38000b21f68c73edc7788ec9
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Mar 1 08:48:30 2021 +0100
ISIS-2554: TypeIdentifier: serialization support
---
.../org/apache/isis/applib/id/TypeIdentifier.java | 34 ++++++++++++++++++++--
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/isis/applib/id/TypeIdentifier.java b/api/applib/src/main/java/org/apache/isis/applib/id/TypeIdentifier.java
index e221081..8c2f2d4 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/id/TypeIdentifier.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/id/TypeIdentifier.java
@@ -18,6 +18,10 @@
*/
package org.apache.isis.applib.id;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.Objects;
import java.util.function.Supplier;
@@ -34,14 +38,23 @@ import lombok.val;
/**
* A generalization of Java's class type to also hold a logical name, which can be supplied lazily.
- *
+ * @apiNote thread-safe and serializable
* @since 2.0 {@index}
*/
@ToString
-public final class TypeIdentifier implements Comparable<TypeIdentifier> {
+public final class TypeIdentifier
+implements
+ Comparable<TypeIdentifier>,
+ Externalizable {
+ /**
+ * Class this identifier represents.
+ *
+ * @implNote in support of de-serialization cannot be declared final
+ * (Java 15+ records will solve this issue)
+ */
@Getter
- private final Class<?> correspondingClass;
+ private /*final*/ Class<?> correspondingClass;
@ToString.Exclude
private final Supplier<String> logicalNameProvider;
@@ -172,6 +185,20 @@ public final class TypeIdentifier implements Comparable<TypeIdentifier> {
return _Strings.compareNullsFirst(correspondingClass.getCanonicalName(), otherClassName);
}
+ // -- SERIALIZATION
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(getCorrespondingClass());
+ out.writeUTF(getLogicalTypeName());
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ this.correspondingClass = (Class<?>) in.readObject();
+ this.logicalName = in.readUTF();
+ }
+
// -- HELPER
private String requireNonEmpty(final String logicalName) {
@@ -182,4 +209,5 @@ public final class TypeIdentifier implements Comparable<TypeIdentifier> {
return logicalName;
}
+
}