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

Clarification on deserialization #67

Closed
ChrisGitWorkshop opened this issue Aug 10, 2024 · 4 comments
Closed

Clarification on deserialization #67

ChrisGitWorkshop opened this issue Aug 10, 2024 · 4 comments
Labels

Comments

@ChrisGitWorkshop
Copy link

Hi,

Can i check whether a nested object in which the child nodes does only have "@id" without "@type" will perform the deserialization using the jb4jsonld ?

This use case come when, i need to refer an already existing person object in the payload which only have a id.

I saw the config property assumeTargetType = true to deal with this (As per my understanding). But it doesn't work as I expected. I am getting the below error There are unresolved references to objects. (Though i noticed, i am getting the targetted Type in debug, but since its not PersistenceProperties#IDENTIFIER_TYPE, not added).

When i do a quick analysis, i found below.

In javaCollectionDeserializer#resolveValue(Map) , there is a conditiona as below

} else if (value.size() == 1 && value.containsKey(JsonLd.ID)) {
   handleReferenceNodeInCollection(value, targetType);
}

So from the above code, the execution goes all the way to DefaultInstanceBuilder#addNodeForREference(String). From here it check for canDirectlyAddNodeReference (targetType), where it check whther the targetted type is any of PersistenceProperties#IDENTIFIER_TYPE, since its adding to pendingReferenceRegistry.

/**
 * Supported identifier Java types.
 * <p>
 * This set represents the Java types that can be used as entity identifiers or as {@link
 * cz.cvut.kbss.jopa.model.annotations.OWLObjectProperty} property values.
 */
public static final Set<Class<?>> IDENTIFIER_TYPES = Set.of(URI.class, URL.class, String.class);

Example object given below.

{
    "@context": {        
        "example": "https://example.model/data#"
    },
    "@type":"example:SocialMediaAccount",
    "example:profileName": "MyNameIsXYZ",
    "example:bestFriend": {
        "@id": "https://socialmedial/account/person/MyBestiee"
    }
}

Any input would be appreciated.

Thanks in advacne,
Chris.

@ledsoft
Copy link
Contributor

ledsoft commented Aug 12, 2024

Hi Chris,
sorry for the delayed response. I think your analysis is pretty much spot on. JB4JSON-LD will assume an object containing only @id is a reference to a fully serialized object. That's why it is put into the PendingReferenceRegistry.

I think it makes sense to be able to circumvent missing @types by using ASSUME_TARGET_TYPE even for objects having only @id. The only question is how to combine it with this reference resolution mechanism, because I don't want to completely disable it when ASSUME_TARGET_TYPE is set to true.

I guess what we can do is register the pending references and after all is deserialized and PendingReferenceRegistry is not empty, check if ASSUME_TARGET_TYPE is true. If so, replace the pending references with objects having only identifier (and being of correct type, of course). If it is false, throw an exception just as we do now. Would this behavior be usable for you?

@ChrisGitWorkshop
Copy link
Author

Dear Team,

Many thanks for finding time to look into this issue, appriciate it.

The suggestion you have put forward sounds good to me. Becuase, when i had a quick look at the jsonld doc, it implicitly saying that @type is not a mandatory filed in the object (I am not an expert in this data structure though :) ). Hence this might be helpful if we could implement it (Much better if we have some configuration in place, for instance as you mentioned to make use of ASSUME_TARGET_TYPE property, so that people can make a choice).

Regards,
Chris.

@ledsoft
Copy link
Contributor

ledsoft commented Aug 15, 2024

I created a follow-up ticket for the discussed enhancement - #69.

@ledsoft
Copy link
Contributor

ledsoft commented Aug 26, 2024

Implemented in 0.15.0.

@ledsoft ledsoft closed this as completed Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants