Stream: hapi
Topic: hapi-fhir-base 5.0.2 JSON parser error
vladimir matryshov (Jul 29 2020 at 14:55):
Hello, I'm having a trouble in FHIR json parser issue.
Here is java code what I couldn't run:
log.debug(fhirContext.newJsonParser().setPrettyPrint(true)
.encodeResourceToString(patient));
I've attached the error log file and sample code file error.txt FhirPatientServiceImpl.java
Is there anyone who can help me?
Jens Villadsen (Jul 29 2020 at 14:56):
It looks like you are trying to parse json as xml
vladimir matryshov (Jul 29 2020 at 15:00):
code:
log.debug("FHIR Patient:");
log.debug(fhirContext.newXmlParser().setPrettyPrint(true)
.encodeResourceToString(patient));
log.debug(fhirContext.newJsonParser().setPrettyPrint(true)
.encodeResourceToString(patient));
Log
2020-07-29 17:18:00.154 DEBUG 10124 --- [http-nio-8461-exec-5] g.s.c.u.s.fhir.FhirPatientServiceImpl : FHIR Patient:
2020-07-29 17:18:00.156 DEBUG 10124 --- [http-nio-8461-exec-5] g.s.c.u.s.fhir.FhirPatientServiceImpl : <Patient xmlns="http://hl7.org/fhir">
<id value="C2S-DEV-0PN6EK"/>
<identifier>
<use value="official"/>
<system value="https://bhits.github.io/consent2share"/>
<value value="C2S-DEV-0PN6EK"/>
</identifier>
<active value="true"/>
<name>
<family value="Test"/>
<given value="Test"/>
</name>
<telecom>
<system value="email"/>
<value value="test@test.com"/>
<use value="home"/>
</telecom>
<gender value="male"/>
<birthDate value="2020-07-01"/>
</Patient>
2020-07-29 17:18:00.162 ERROR 10124 --- [http-nio-8461-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class ca.uhn.fhir.parser.json.jackson.JacksonStructure] with root cause
java.lang.NoClassDefFoundError: Could not initialize class ca.uhn.fhir.parser.json.jackson.JacksonStructure
at ca.uhn.fhir.parser.JsonParser.createJsonWriter(JsonParser.java:166) ~[hapi-fhir-base-5.0.2.jar:na]
at ca.uhn.fhir.parser.JsonParser.doEncodeResourceToWriter(JsonParser.java:183) ~[hapi-fhir-base-5.0.2.jar:na]
at ca.uhn.fhir.parser.BaseParser.encodeResourceToWriter(BaseParser.java:419) ~[hapi-fhir-base-5.0.2.jar:na]
at ca.uhn.fhir.parser.BaseParser.encodeResourceToWriter(BaseParser.java:403) ~[hapi-fhir-base-5.0.2.jar:na]
at ca.uhn.fhir.parser.BaseParser.encodeResourceToString(BaseParser.java:392) ~[hapi-fhir-base-5.0.2.jar:na]
at gov.samhsa.c2s.ums.service.fhir.FhirPatientServiceImpl.publishFhirPatient(FhirPatientServiceImpl.java:101) ~[classes/:na]
at gov.samhsa.c2s.ums.service.UserServiceImpl.registerUser(UserServiceImpl.java:179) ~[classes/:na]
at gov.samhsa.c2s.ums.service.UserServiceImpl$$FastClassBySpringCGLIB$$3f457b5d.invoke(<generated>) ~[classes/:na]
vladimir matryshov (Jul 29 2020 at 15:02):
It seems to be working for XML parsing but not working on JSON parsing.
vladimir matryshov (Jul 29 2020 at 15:15):
I've tried to run it on hapi-fhir-base 5.0.1 and I got the different error.
2020-07-29 18:10:53.430 DEBUG 19980 --- [http-nio-8461-exec-2] g.s.c.u.s.fhir.FhirPatientServiceImpl : FHIR Patient:
2020-07-29 18:10:54.372 DEBUG 19980 --- [http-nio-8461-exec-2] g.s.c.u.s.fhir.FhirPatientServiceImpl : <Patient xmlns="http://hl7.org/fhir">
<id value="C2S-DEV-BTN33I"/>
<identifier>
<use value="official"/>
<system value="https://bhits.github.io/consent2share"/>
<value value="C2S-DEV-BTN33I"/>
</identifier>
<active value="true"/>
<name>
<family value="Test"/>
<given value="Test"/>
</name>
<telecom>
<system value="email"/>
<value value="test@test.com"/>
<use value="home"/>
</telecom>
<gender value="male"/>
<birthDate value="2020-07-01"/>
</Patient>
2020-07-29 18:10:54.392 ERROR 19980 --- [http-nio-8461-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchFieldError: FAIL_ON_TRAILING_TOKENS] with root cause
java.lang.NoSuchFieldError: FAIL_ON_TRAILING_TOKENS
at ca.uhn.fhir.parser.json.jackson.JacksonStructure.createObjectMapper(JacksonStructure.java:384) ~[hapi-fhir-base-5.0.1.jar:na]
at ca.uhn.fhir.parser.json.jackson.JacksonStructure.<clinit>(JacksonStructure.java:55) ~[hapi-fhir-base-5.0.1.jar:na]
at ca.uhn.fhir.parser.JsonParser.createJsonWriter(JsonParser.java:166) ~[hapi-fhir-base-5.0.1.jar:na]
at ca.uhn.fhir.parser.JsonParser.doEncodeResourceToWriter(JsonParser.java:183) ~[hapi-fhir-base-5.0.1.jar:na]
at ca.uhn.fhir.parser.BaseParser.encodeResourceToWriter(BaseParser.java:419) ~[hapi-fhir-base-5.0.1.jar:na]
at ca.uhn.fhir.parser.BaseParser.encodeResourceToWriter(BaseParser.java:403) ~[hapi-fhir-base-5.0.1.jar:na]
at ca.uhn.fhir.parser.BaseParser.encodeResourceToString(BaseParser.java:392) ~[hapi-fhir-base-5.0.1.jar:na]
at gov.samhsa.c2s.ums.service.fhir.FhirPatientServiceImpl.publishFhirPatient(FhirPatientServiceImpl.java:101) ~[classes/:na]
at gov.samhsa.c2s.ums.service.UserServiceImpl.registerUser(UserServiceImpl.java:179) ~[classes/:na]
at gov.samhsa.c2s.ums.service.UserServiceImpl$$FastClassBySpringCGLIB$$3f457b5d.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) ~[spring-aop-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) ~[spring-aop-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at gov.samhsa.c2s.ums.service.UserServiceImpl$$EnhancerBySpringCGLIB$$cb29ba66.registerUser(<generated>) ~[classes/:na]
at gov.samhsa.c2s.ums.web.UserRestController.registerUser(UserRestController.java:42) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_251]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_251]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_251]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_251]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:110) ~[spring-boot-actuator-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:208) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
Jens Villadsen (Jul 29 2020 at 15:15):
The noclassdeffound tells me that there are issues on your classpath
vladimir matryshov (Jul 29 2020 at 15:16):
How can I solve the issue?
vladimir matryshov (Jul 29 2020 at 15:17):
Here is pom file.
pom.xml
Jens Villadsen (Jul 29 2020 at 20:08):
1) I recommend sticking with version 5.0.2
2) did you provide the full stack trace?
3) the jackson deps that you get when using spring-boot-starter-parent/1.5.6.RELEASE brings jackson version 2.8.9 whereas HAPI brings 2.10.0. I don't know if that could be the cause
Last updated: Apr 12 2022 at 19:14 UTC