Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in deserializing S3BucketResourceDefinition #338

Closed
ndr-brt opened this issue Jun 4, 2024 · 1 comment · Fixed by #339
Closed

error in deserializing S3BucketResourceDefinition #338

ndr-brt opened this issue Jun 4, 2024 · 1 comment · Fixed by #339
Labels
bug Something isn't working

Comments

@ndr-brt
Copy link
Member

ndr-brt commented Jun 4, 2024

error detail

SEVERE 2024-05-31T14:11:56.901014111 StateMachineManager [TransferProcessManagerImpl] error caught
 Caused by: org.eclipse.edc.spi.persistence.EdcPersistenceException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.eclipse.edc.connector.transfer.spi.types.ResourceDefinition$Builder` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
connectorb             |  at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 57] (through reference chain: org.eclipse.edc.connector.transfer.spi.types.ResourceManifest$Builder["definitions"]->java.util.ArrayList[0])
connectorb             |        at org.eclipse.edc.sql.store.AbstractSqlStore.fromJson(AbstractSqlStore.java:94)
connectorb             |        at org.eclipse.edc.connector.store.sql.transferprocess.store.SqlTransferProcessStore.mapTransferProcess(SqlTransferProcessStore.java:309)
connectorb             |        at org.eclipse.edc.sql.SqlQueryExecutor$1.tryAdvance(SqlQueryExecutor.java:128)
connectorb             |        ... 27 more
connectorb             | Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.eclipse.edc.connector.transfer.spi.types.ResourceDefinition$Builder` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
connectorb             |  at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 57] (through reference chain: org.eclipse.edc.connector.transfer.spi.types.ResourceManifest$Builder["definitions"]->java.util.ArrayList[0])
connectorb             |        at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
connectorb             |        at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1887)
connectorb             |        at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:414)
connectorb             |        at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1375)
connectorb             |        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1508)
connectorb             |        at com.fasterxml.jackson.databind.deser.BuilderBasedDeserializer.deserializeFromObject(BuilderBasedDeserializer.java:319)
connectorb             |        at com.fasterxml.jackson.databind.deser.BuilderBasedDeserializer.deserialize(BuilderBasedDeserializer.java:240)
connectorb             |        at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:170)
connectorb             |        at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:136)
connectorb             |        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeWithType(BeanDeserializerBase.java:1380)
connectorb             |        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer._deserializeFromArray(CollectionDeserializer.java:361)
connectorb             |        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:244)
connectorb             |        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:28)
connectorb             |        at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeSetAndReturn(MethodProperty.java:158)
connectorb             |        at com.fasterxml.jackson.databind.deser.BuilderBasedDeserializer.vanillaDeserialize(BuilderBasedDeserializer.java:293)
connectorb             |        at com.fasterxml.jackson.databind.deser.BuilderBasedDeserializer.deserialize(BuilderBasedDeserializer.java:217)
connectorb             |        at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
connectorb             |        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4899)
connectorb             |        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3846)
connectorb             |        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3814)
connectorb             |        at org.eclipse.edc.sql.store.AbstractSqlStore.fromJson(AbstractSqlStore.java:92)
connectorb             |        ... 29 more

How

looks to be a bug in the S3BucketResourceDefinition class, it misses the jackson annotations needed for deserialization.

This test is broken:

    @Test
    void deserialization() throws JsonProcessingException {
        var json = "{\"definitions\":[{\"edctype\":\"S3BucketResourceDefinition\",\"id\":\"bc33869d-f6f8-40d6-8c25-a06d2498925b\",\"transferProcessId\":\"27da1d9a-660a-4466-8044-cd4002e39970\",\"regionId\":\"eu-central-1\",\"bucketName\":\"<my-bucket>\"}]}";

        var jacksonTypeManager = new JacksonTypeManager();
        jacksonTypeManager.registerTypes(S3BucketResourceDefinition.class);
        var objectMapper = jacksonTypeManager.getMapper();

        var resourceDefinition = objectMapper.readValue(json, ResourceManifest.class);

        assertThat(resourceDefinition).isNotNull();
    }

to make it work we need to add the jackson annotations on S3BucketResourceDefinition:

@JsonDeserialize(builder = S3BucketResourceDefinition.Builder.class)
public class S3BucketResourceDefinition extends ResourceDefinition {
    private String regionId;
    private String bucketName;
    private Supplier<Boolean> checker;

    private S3BucketResourceDefinition() {
    }

    public String getRegionId() {
        return regionId;
    }

    public String getBucketName() {
        return bucketName;
    }

    @Override
    public Builder toBuilder() {
        return initializeBuilder(new Builder())
                .regionId(regionId)
                .bucketName(bucketName);
    }

    @JsonPOJOBuilder(withPrefix = "")
    public static class Builder extends ResourceDefinition.Builder<S3BucketResourceDefinition, Builder> {

        public Builder() {
            super(new S3BucketResourceDefinition());
        }

        @JsonCreator
        public static Builder newInstance() {
            return new Builder();
        }

        public Builder regionId(String regionId) {
            resourceDefinition.regionId = regionId;
            return this;
        }

        public Builder bucketName(String bucketName) {
            resourceDefinition.bucketName = bucketName;
            return this;
        }

        @Override
        protected void verify() {
            super.verify();
            Objects.requireNonNull(resourceDefinition.regionId, "regionId");
            Objects.requireNonNull(resourceDefinition.bucketName, "bucketName");
        }
    }

this discussion deserves to stay in the Technology-Aws repository, will open a bug report as well.

Originally posted by @ndr-brt in #337 (reply in thread)

@github-actions github-actions bot added the triage all new issues awaiting classification label Jun 4, 2024
@ndr-brt ndr-brt added bug Something isn't working and removed triage all new issues awaiting classification labels Jun 4, 2024
Copy link

github-actions bot commented Jun 4, 2024

Thanks for your contribution 🔥 We will take a look asap 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant