Skip to content

Commit

Permalink
fix: apply polymorphic to Dataset for serde (#4362)
Browse files Browse the repository at this point in the history
* fix: apply polymorphic to Dataset for serde

* chore: deps file
  • Loading branch information
wolf4ood authored Jul 15, 2024
1 parent efdbb10 commit 4ca4906
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ maven/mavencentral/com.networknt/json-schema-validator/1.0.76, Apache-2.0, appro
maven/mavencentral/com.nimbusds/nimbus-jose-jwt/9.28, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.nimbusds/nimbus-jose-jwt/9.40, Apache-2.0, approved, #15156
maven/mavencentral/com.puppycrawl.tools/checkstyle/10.17.0, LGPL-2.1-or-later AND (Apache-2.0 AND LGPL-2.1-or-later) AND Apache-2.0, approved, #15077
maven/mavencentral/com.samskivert/jmustache/1.15, BSD-2-Clause, approved, clearlydefined
maven/mavencentral/com.samskivert/jmustache/1.15, BSD-2-Clause AND BSD-3-Clause, approved, clearlydefined
maven/mavencentral/com.squareup.okhttp3/okhttp-dnsoverhttps/4.12.0, Apache-2.0, approved, #11159
maven/mavencentral/com.squareup.okhttp3/okhttp/4.12.0, Apache-2.0, approved, #15227
maven/mavencentral/com.squareup.okhttp3/okhttp/4.9.3, Apache-2.0 AND MPL-2.0, approved, #3225
Expand Down Expand Up @@ -225,7 +225,7 @@ maven/mavencentral/org.apache.maven.doxia/doxia-module-xdoc/1.12.0, Apache-2.0,
maven/mavencentral/org.apache.maven.doxia/doxia-sink-api/1.12.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.apache.velocity.tools/velocity-tools-generic/3.1, Apache-2.0, approved, #9331
maven/mavencentral/org.apache.velocity/velocity-engine-core/2.3, Apache-2.0, approved, #2478
maven/mavencentral/org.apache.velocity/velocity-engine-scripting/2.3, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.apache.velocity/velocity-engine-scripting/2.3, Apache-2.0, restricted, clearlydefined
maven/mavencentral/org.apache.xbean/xbean-reflect/3.7, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.apiguardian/apiguardian-api/1.1.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.assertj/assertj-core/3.26.0, Apache-2.0, approved, #14886
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.eclipse.edc.connector.controlplane.catalog.spi;

import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

Expand All @@ -25,6 +26,7 @@
* Entity representing a Catalog
*/
@JsonDeserialize(builder = Catalog.Builder.class)
@JsonTypeName("dataspaceconnector:catalog")
public class Catalog extends Dataset {
protected final List<Dataset> datasets = new ArrayList<>();
protected List<DataService> dataServices = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.spi.types.domain.Polymorphic;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -33,7 +35,8 @@
* different policies and may be available via different distributions.
*/
@JsonDeserialize(builder = Dataset.Builder.class)
public class Dataset {
@JsonTypeName("dataspaceconnector:dataset")
public class Dataset implements Polymorphic {

/**
* Policies under which this Dataset is available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.edc.json.JacksonTypeManager;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.spi.types.TypeManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.List;
Expand All @@ -28,14 +29,21 @@ class CatalogSerializationTest {

private final TypeManager typeManager = new JacksonTypeManager();

@BeforeEach
void beforeAll() {
typeManager.registerTypes(Catalog.class, Dataset.class);
}

@Test
void verifySerialization() {
var catalog = createCatalog();

var json = typeManager.writeValueAsString(catalog);

var deserialized = typeManager.readValue(json, Catalog.class);
assertThat(deserialized).usingRecursiveComparison().isEqualTo(catalog);
assertThat(catalog).usingRecursiveComparison().isEqualTo(deserialized);

assertThat(catalog.getDatasets().get(1)).isInstanceOf(Catalog.class);
}


Expand All @@ -51,10 +59,13 @@ private Catalog createCatalog() {
.distributions(List.of(distribution))
.build();


var nestedCatalog = Catalog.Builder.newInstance().id("nestedId").participantId("participantId").build();

return Catalog.Builder.newInstance()
.id("id")
.dataServices(List.of(dataService))
.datasets(List.of(dataset))
.datasets(List.of(dataset, nestedCatalog))
.property("prop", "propValue")
.build();
}
Expand Down

0 comments on commit 4ca4906

Please sign in to comment.