org.hl7.fhir.dstu3.model.Claim cannot be cast to ca.uhn.fhir.model.api.IResource

564 views
Skip to first unread message

vj

unread,
Aug 30, 2016, 1:57:55 PM8/30/16
to HAPI FHIR, Vijay Ratnagiri
Hello All,

I'm just starting to use HAPI-FHIR and I was able to successfully parse a claim resource. However, when I try to parse a bundle, I get the following exception:

org.hl7.fhir.dstu3.model.Claim cannot be cast to ca.uhn.fhir.model.api.IResource
java.lang.ClassCastException: org.hl7.fhir.dstu3.model.Claim cannot be cast to ca.uhn.fhir.model.api.IResource
at ca.uhn.fhir.parser.ParserState$PreResourceStateHapi.populateTarget(ParserState.java:2240)
at ca.uhn.fhir.parser.ParserState$PreResourceState.postProcess(ParserState.java:2158)
at ca.uhn.fhir.parser.ParserState$PreResourceState.wereBack(ParserState.java:2080)
at ca.uhn.fhir.parser.ParserState$PreResourceStateHapi.wereBack(ParserState.java:2249)
at ca.uhn.fhir.parser.ParserState.pop(ParserState.java:161)
at ca.uhn.fhir.parser.ParserState.access$100(ParserState.java:96)
at ca.uhn.fhir.parser.ParserState$ElementCompositeState.endingElement(ParserState.java:1572)
at ca.uhn.fhir.parser.ParserState.endingElement(ParserState.java:133)
at ca.uhn.fhir.parser.JsonParser.parseChildren(JsonParser.java:1293)
at ca.uhn.fhir.parser.JsonParser.parseBundleChildren(JsonParser.java:1189)
at ca.uhn.fhir.parser.JsonParser.parseBundleChildren(JsonParser.java:1128)
at ca.uhn.fhir.parser.JsonParser.parseBundle(JsonParser.java:1110)
at ca.uhn.fhir.parser.BaseParser.parseBundle(BaseParser.java:585)
at ca.uhn.fhir.parser.BaseParser.parseBundle(BaseParser.java:591)
at com.verscend.fhir.FHIRParser.parse(FHIRParser.groovy:12)
at com.verscend.fhir.FHIRParserTest.Claim JSON Bundle Can Be Parsed Successfully(FHIRParserTest.groovy:15)


What should I change in the parser code below to get this working?

import ca.uhn.fhir.context.FhirContext
import org.hl7.fhir.dstu3.model.Bundle

class FHIRParser {

  FhirContext context = FhirContext.forDstu3()

  Bundle parse(String jsonPath) {
    def parser = context.newJsonParser()
    parser.parseBundle(new File(jsonPath).text)
  }
}

Thanks!

James Agnew

unread,
Aug 30, 2016, 2:02:00 PM8/30/16
to vj, HAPI FHIR, Vijay Ratnagiri
Hi Vijay,

What version of HAPI is this happening with?

Cheers,
James

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+unsubscribe@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/56223fcc-a02f-4f90-b1bf-84e425bc3d69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vratn...@gmail.com

unread,
Aug 30, 2016, 2:11:39 PM8/30/16
to HAPI FHIR, vratn...@veriskhealth.com, vratn...@gmail.com
Hello James,

I'm using ca.uhn.hapi.fhir:hapi-fhir-structures-dstu3:1.6.

Thanks!

James Agnew

unread,
Sep 1, 2016, 3:25:47 PM9/1/16
to vj, HAPI FHIR, Vijay Ratnagiri
Ah, I see the issue.

parseBundle is actually only intended to be used on DSTU1 code. For DSTU2/3 you should be using "parser.parseResource(Bundle.class, foo)"

Cheers,
James

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+unsubscribe@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages