This is an automated email from the ASF dual-hosted git repository.
andreapatricelli pushed a commit to branch 4_0_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/4_0_X by this push:
new 88878f9864 [SYNCOPE-1879] managing ConnectorObjectIdentification
serialization/deserialization (#1076)
88878f9864 is described below
commit 88878f986404a20666a646c59515e672b2a8f6ea
Author: Andrea Patricelli <[email protected]>
AuthorDate: Mon May 12 14:34:40 2025 +0200
[SYNCOPE-1879] managing ConnectorObjectIdentification
serialization/deserialization (#1076)
---
.../ConnectorObjectIdentificationDeserializer.java | 67 ++++++++++++++++++++++
.../ConnectorObjectIdentificationSerializer.java | 54 +++++++++++++++++
.../provisioning/api/serialization/POJOHelper.java | 4 ++
.../ConnObjectIdentificationDeserializerTest.java | 43 ++++++++++++++
.../ConnObjectIdentificationSerializerTest.java | 58 +++++++++++++++++++
5 files changed, 226 insertions(+)
diff --git
a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/ConnectorObjectIdentificationDeserializer.java
b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/ConnectorObjectIdentificationDeserializer.java
new file mode 100644
index 0000000000..ef086e569b
--- /dev/null
+++
b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/ConnectorObjectIdentificationDeserializer.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.provisioning.api.serialization;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.identityconnectors.framework.common.objects.Attribute;
+import org.identityconnectors.framework.common.objects.AttributeBuilder;
+import
org.identityconnectors.framework.common.objects.ConnectorObjectIdentification;
+import org.identityconnectors.framework.common.objects.Name;
+import org.identityconnectors.framework.common.objects.ObjectClass;
+import org.identityconnectors.framework.common.objects.Uid;
+
+public class ConnectorObjectIdentificationDeserializer
+ extends AbstractValueDeserializer<ConnectorObjectIdentification> {
+ @Override
+ public ConnectorObjectIdentification deserialize(final JsonParser jp,
+ final DeserializationContext deserializationContext) throws
IOException {
+
+ ObjectNode tree = jp.readValueAsTree();
+
+ String objectClass = tree.get("objectClass").asText();
+
+ Set<Attribute> attributes = new HashSet<>();
+ JsonNode attributesNode = tree.get("attributes");
+ if (attributesNode != null && attributesNode.isArray()) {
+ attributesNode.forEach(attrNode -> {
+ try {
+ String name = attrNode.get("name").asText();
+ List<Object> values = doDeserialize(attrNode.get("value"),
jp);
+ attributes.add(Uid.NAME.equals(name)
+ ? new Uid(values.isEmpty() || values.getFirst() ==
null
+ ? null : values.getFirst().toString())
+ : Name.NAME.equals(name)
+ ? new Name(values.isEmpty() ||
values.getFirst() == null
+ ? null : values.getFirst().toString())
+ : AttributeBuilder.build(name, values));
+ } catch (IOException e) {
+ }
+ });
+ }
+
+ return new ConnectorObjectIdentification(new ObjectClass(objectClass),
attributes);
+ }
+}
diff --git
a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/ConnectorObjectIdentificationSerializer.java
b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/ConnectorObjectIdentificationSerializer.java
new file mode 100644
index 0000000000..088ab5304e
--- /dev/null
+++
b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/ConnectorObjectIdentificationSerializer.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.provisioning.api.serialization;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import java.io.IOException;
+import
org.identityconnectors.framework.common.objects.ConnectorObjectIdentification;
+
+public class ConnectorObjectIdentificationSerializer extends
AbstractValueSerializer<ConnectorObjectIdentification> {
+
+ @Override
+ public void serialize(final ConnectorObjectIdentification value, final
JsonGenerator jgen,
+ final SerializerProvider serializerProvider) throws IOException {
+ jgen.writeStartObject();
+
+ jgen.writeStringField("objectClass",
value.getObjectClass().getObjectClassValue());
+
+ jgen.writeFieldName("attributes");
+
+ jgen.writeStartArray();
+ value.getAttributes().forEach(attr -> {
+ try {
+ jgen.writeStartObject();
+
+ jgen.writeStringField("name", attr.getName());
+
+ jgen.writeFieldName("value");
+ doSerialize(attr.getValue(), jgen);
+ jgen.writeEndObject();
+ } catch (IOException e) {
+ }
+ });
+ jgen.writeEndArray();
+
+ jgen.writeEndObject();
+ }
+}
diff --git
a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/POJOHelper.java
b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/POJOHelper.java
index ba65dffa00..f152a61663 100644
---
a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/POJOHelper.java
+++
b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/POJOHelper.java
@@ -28,6 +28,7 @@ import
org.apache.syncope.core.provisioning.api.propagation.PropagationTaskInfo;
import org.identityconnectors.common.security.GuardedString;
import org.identityconnectors.framework.common.objects.Attribute;
import org.identityconnectors.framework.common.objects.AttributeDelta;
+import
org.identityconnectors.framework.common.objects.ConnectorObjectIdentification;
import org.identityconnectors.framework.common.objects.SyncToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,11 +48,14 @@ public final class POJOHelper {
pojoModule.addSerializer(Attribute.class, new AttributeSerializer());
pojoModule.addSerializer(AttributeDelta.class, new
AttributeDeltaSerializer());
pojoModule.addSerializer(SyncToken.class, new SyncTokenSerializer());
+ pojoModule.addSerializer(ConnectorObjectIdentification.class, new
ConnectorObjectIdentificationSerializer());
pojoModule.addSerializer(PropagationTaskInfo.class, new
PropagationTaskInfoSerializer());
pojoModule.addDeserializer(GuardedString.class, new
GuardedStringDeserializer());
pojoModule.addDeserializer(Attribute.class, new
AttributeDeserializer());
pojoModule.addDeserializer(AttributeDelta.class, new
AttributeDeltaDeserializer());
pojoModule.addDeserializer(SyncToken.class, new
SyncTokenDeserializer());
+ pojoModule.addDeserializer(ConnectorObjectIdentification.class,
+ new ConnectorObjectIdentificationDeserializer());
MAPPER = JsonMapper.builder().
addModule(pojoModule).
diff --git
a/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/serialization/ConnObjectIdentificationDeserializerTest.java
b/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/serialization/ConnObjectIdentificationDeserializerTest.java
new file mode 100644
index 0000000000..6dd867ce1e
--- /dev/null
+++
b/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/serialization/ConnObjectIdentificationDeserializerTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.provisioning.api.serialization;
+
+import java.io.IOException;
+import java.util.Set;
+import org.apache.syncope.core.provisioning.api.AbstractTest;
+import org.identityconnectors.framework.common.objects.AttributeBuilder;
+import
org.identityconnectors.framework.common.objects.ConnectorObjectIdentification;
+import org.identityconnectors.framework.common.objects.ObjectClass;
+import org.identityconnectors.framework.common.objects.Uid;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class ConnObjectIdentificationDeserializerTest extends AbstractTest {
+
+ @Test
+ public void deserialize() throws IOException {
+ ConnectorObjectIdentification source = new
ConnectorObjectIdentification(ObjectClass.ACCOUNT,
+ Set.of(AttributeBuilder.build(Uid.NAME, "someuid")));
+
+ ConnectorObjectIdentification deserialized =
+ POJOHelper.deserialize(POJOHelper.serialize(source),
ConnectorObjectIdentification.class);
+
+ Assertions.assertEquals(deserialized,
deserialized.getIdentification());
+ }
+}
diff --git
a/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/serialization/ConnObjectIdentificationSerializerTest.java
b/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/serialization/ConnObjectIdentificationSerializerTest.java
new file mode 100644
index 0000000000..fe4608bc93
--- /dev/null
+++
b/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/serialization/ConnObjectIdentificationSerializerTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.provisioning.api.serialization;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import java.io.IOException;
+import java.util.Set;
+import org.apache.syncope.core.provisioning.api.AbstractTest;
+import org.identityconnectors.framework.common.objects.AttributeBuilder;
+import
org.identityconnectors.framework.common.objects.ConnectorObjectIdentification;
+import org.identityconnectors.framework.common.objects.ObjectClass;
+import org.identityconnectors.framework.common.objects.Uid;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+
+public class ConnObjectIdentificationSerializerTest extends AbstractTest {
+
+ @Test
+ public void serialize(
+ final @Mock JsonGenerator jgen,
+ final @Mock SerializerProvider sp)
+ throws IOException {
+ ConnectorObjectIdentification source = new
ConnectorObjectIdentification(ObjectClass.ACCOUNT,
+ Set.of(AttributeBuilder.build(Uid.NAME, "someuid")));
+
+ new ConnectorObjectIdentificationSerializer().serialize(source, jgen,
sp);
+ verify(jgen, times(2)).writeStartObject();
+ verify(jgen).writeStringField(eq("objectClass"),
eq(ObjectClass.ACCOUNT.getObjectClassValue()));
+ verify(jgen).writeFieldName("attributes");
+ verify(jgen).writeFieldName("value");
+ verify(jgen).writeStringField(eq("name"), eq(Uid.NAME));
+ verify(jgen, times(2)).writeStartArray();
+ verify(jgen).writeString("someuid");
+ verify(jgen, times(2)).writeEndArray();
+ verify(jgen, times(2)).writeEndObject();
+ }
+}