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

openEHR SDK fails to serialize and deSerialize ContributionCreateDTO with ObjectMapper #452

Open
2 tasks done
flowrider3000 opened this issue Apr 24, 2023 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@flowrider3000
Copy link

Before reporting an issue

  • I have searched existing issues
  • I have reproduced the issue with the latest release

Environment information

  • openEHR_SDK version 1.26.0

Steps to reproduce

@Test
void serializeAndDeserializeContributionWithObjectMapper() throws Exception {
   Composition composition = new CanonicalJson()
           .unmarshal(FileUtil.readTestResourceFromFile("compositions/compo_feeder_audit_details.json"), Composition.class);

   ObjectMapper objectMapper = new ObjectMapper();
   SimpleModule module = new SimpleModule("openEHR", new Version(1, 0, 0, null, null, null));
   module.addDeserializer(AuditDetails.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(Composition.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(Contribution.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(DvCodedText.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(DvText.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(EhrStatus.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(Folder.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(HierObjectId.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(ItemStructure.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(ObjectRef.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(ObjectVersionId.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(UIDBasedId.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(RevisionHistoryItem.class, new RmObjectJsonDeSerializer());
   module.addDeserializer(VersionedComposition.class, new RmObjectJsonDeSerializer());

   objectMapper.registerModule(module);
   objectMapper.registerModule(new JavaTimeModule());

   ContributionCreateDto contributionCreateDto = ContributionBuilder.builder(createAuditDetails())
           .addCompositionCreation(composition)
           .build();

   String serializedContribution = objectMapper.writeValueAsString(contributionCreateDto);

   ContributionCreateDto deserializedContribution = objectMapper.readValue(serializedContribution, ContributionCreateDto.class);

   assertNotNull(deserializedContribution);
}

Notes:

{
  "_type": "AUDIT_DETAILS",
  "system_id": "test-system-id",
  "committer": {
     "_type": "PARTY_IDENTIFIED",
     "name": "<optional name of the committer>",
     "external_ref": {
       "id": {
         "_type": "GENERIC_ID",
         "value": "<OBJECT_ID>",
         "scheme": "<ID SCHEME NAME>"
       },
       "namespace": "demographic",
       "type": "PERSON"
     }
  },
  "change_type": {
     "value": "creation",
     "defining_code": {
       "terminology_id": {
         "value": "openehr"
       },
       "code_string": "249"
     }
  },
  "description": {
     "value": "<optional audit description>"
  }
}

Expected behavior

   ContributionCreateDto deserializedContribution = objectMapper.readValue(serializedContribution, ContributionCreateDto.class);

objectMapper.readValue(...) should return a ContributionCreateDto.

Actual result

objectMapper.readValue(...) fails with the following stacktrace

com.fasterxml.jackson.databind.JsonMappingException: Could not resolve subtype of [simple type, class com.nedap.archie.rm.RMObject]: missing type id property '_type'
at [Source: (String)"{"systemId":"test-system-id","timeCommitted":null,"changeType":{"value":"creation","hyperlink":null,"formatting":null,"mappings":[],"language":null,"encoding":null,"definingCode":{"terminologyId":{"value":"openehr"},"codeString":"249","preferredTerm":null}},"description":{"value":"<optional audit description>","hyperlink":null,"formatting":null,"mappings":[],"language":null,"encoding":null},"committer":{"externalRef":{"namespace":"demographic","type":"PERSON","id":{"value":"<OBJECT_ID>","scheme""[truncated 82 chars]; line: 1, column: 582] (through reference chain: org.ehrbase.response.openehr.ContributionCreateDto["audit"])

   at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:402)
   at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:361)
   at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1826)
   at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:316)
   at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177)
   at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
   at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4730)
   at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3677)
   at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3645)

Further information

cc @stefanspiska , @pfeild, @vidi42

@flowrider3000 flowrider3000 added the bug Something isn't working label Apr 24, 2023
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

No branches or pull requests

1 participant