onaled777
asked on
Spring not serializing Fhir Object Despite using @JsonIgnore
This is the error I see when I try to deploy to Jboss:
This is the method call that is giving the issue:
And this is the object it refers to:
This is a dependency that had to be included in the pom.xml file:
Can someone explain how to get rid of the error?
Based on this post (http://stackoverflow.com/questions/6346018/deserializing-json-into-object-with-overloaded-methods-using-jackson) I tried to add the JsonIgnore annotation to the bean and also to use a MixIn class and but the same error occurred. My attempt in the first case shown below:
Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./ProblemsDataService" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./ProblemsDataService: java.lang.RuntimeException: java.lang.IllegalArgumentException: Conflicting setter definitions for property \"id\": ca.uhn.fhir.model.api.BaseIdentifiableElement#setId(1 params) vs ca.uhn.fhir.model.api.BaseIdentifiableElement#setId(1 params) Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Conflicting setter definitions for property \"id\": ca.uhn.fhir.model.api.BaseIdentifiableElement#setId(1 params) vs ca.uhn.fhir.model.api.BaseIdentifiableElement#setId(1 params) Caused by: java.lang.IllegalArgumentException: Conflicting setter definitions for property \"id\": ca.uhn.fhir.model.api.BaseIdentifiableElement#setId(1 params) vs ca.uhn.fhir.model.api.BaseIdentifiableElement#setId(1 params)"}}
This is the method call that is giving the issue:
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.primitive.IdDt;
import com.x.fhir.FhirCondition;
import com.x.fhir.FhirOrder;
import com.x.responses.ErrorResponse;
import com.x.service.ProblemsService;
import com.fasterxml.jackson.annotation.JsonIgnore;
@RestController
@RequestMapping("/problems")
@Api(value = "Patients Problems", description = "Endpoint for Patient Problems")
public class ProblemController {
@Autowired
ProblemsService patProblemService;
/**
* Get a Patient information
*
* @param id
* @return
* @throws java.lang.Exception
*/
@SuppressWarnings("rawtypes")
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/bean/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(tags = "Fhir Patients Information", httpMethod = "GET", value = "Get Fhir Patient Information", notes = "Get Fhir Patient Information.")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 401, message = "Unauthorized", response = ErrorResponse.class),
@ApiResponse(code = 403, message = "Forbidden", response = ErrorResponse.class),
@ApiResponse(code = 404, message = "Not Found", response = ErrorResponse.class)})
public Bundle searchFhirOrder(@PathVariable("id") long id) throws Exception {
List<FhirOrder> lstFhirOrder = new ArrayList<FhirOrder>();
FhirOrder fo = new FhirOrder();
lstFhirOrder.add(fo);
Iterator i = lstFhirOrder.iterator();
Bundle bundleCondition = new Bundle();
while (i.hasNext())
bundleCondition.addEntry().setResource((FhirOrder)i.next());
return bundleCondition;
}
}
And this is the object it refers to:
package com.x.fhir;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.dstu2.resource.Order;
@ResourceDef(name="Order")
public class FhirOrder extends Order implements java.io.Serializable {
private static final long serialVersionUID = 1L;
}
This is a dependency that had to be included in the pom.xml file:
<!-- HAPI -->
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-base</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu2</artifactId>
<version>1.6</version>
</dependency>
Can someone explain how to get rid of the error?
Based on this post (http://stackoverflow.com/questions/6346018/deserializing-json-into-object-with-overloaded-methods-using-jackson) I tried to add the JsonIgnore annotation to the bean and also to use a MixIn class and but the same error occurred. My attempt in the first case shown below:
package com.x.fhir;
import org.hl7.fhir.instance.model.api.IIdType;
import com.fasterxml.jackson.annotation.JsonIgnore;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.dstu2.resource.BaseResource;
import ca.uhn.fhir.model.dstu2.resource.Order;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.IdDt;
@ResourceDef(name="Order")
public class FhirOrder extends Order implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@JsonIgnore
public BaseResource setId(String theId){
return super.setId(theId);
}
@JsonIgnore
public BaseResource setId(IIdType theId){
return super.setId(theId);
}
@JsonIgnore
public void setId(IdDt theId){
super.setId(theId);
}
@JsonIgnore
public Order setDate(DateTimeDt theValue){
return super.setDate(theValue);
}
@JsonIgnore
public IdDt getId(){
return super.getId();
}
}
Could you post the error again, using word wrap? Too hard to see on single line.
ASKER
Here you go:
Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deploymen t.default- server.def ault-host. /ProblemsD ataService " => "org.jboss.msc.service.Sta rtExceptio n in service jboss.undertow.deployment. default-se rver.defau lt-host./P roblemsDat aService: java.lang.RuntimeException : java.lang.IllegalArgumentE xception: Conflicting setter definitions for property \"id\": ca.uhn.fhir.model.api.Base Identifiab leElement# setId(1 params) vs ca.uhn.fhir.model.api.Base Identifiab leElement# setId(1 params) Caused by: java.lang.RuntimeException : java.lang.IllegalArgumentE xception: Conflicting setter definitions for property \"id\": ca.uhn.fhir.model.api.Base Identifiab leElement# setId(1 params) vs ca.uhn.fhir.model.api.Base Identifiab leElement# setId(1 params) Caused by: java.lang.IllegalArgumentE xception: Conflicting setter definitions for property \"id\": ca.uhn.fhir.model.api.Base Identifiab leElement# setId(1 params) vs ca.uhn.fhir.model.api.Base Identifiab leElement# setId(1 params)"}}
Please choose a file that you want to deploy.
Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deploymen
Please choose a file that you want to deploy.
ASKER
These are the docs for the ca.uhn.fhir.model.dstu2.re source.Ord er object:
http://hapifhir.io/apidocs-dstu2/index.html?ca/uhn/fhir/model/dstu2/resource/class-use/Order.html
http://hapifhir.io/apidocs-dstu2/index.html?ca/uhn/fhir/model/dstu2/resource/class-use/Order.html
I'd like to see ca.uhn.fhir.model.api.Base Identifiab leElement and how it is related to the other class.
ASKER
I believe it must be from the setId(IdDt id) method that is inherited by Order(http://hapifhir.io/apidocs-dstu2/index.html?ca/uhn/fhir/model/dstu2/resource/class-use/Order.html) from the BaseResource class.
public void setId(IdDt theId)
This is the hierarchy for Order:
java.lang.Object
ca.uhn.fhir.model.api.Base Element
ca.uhn.fhir.model.dstu2.re source.Bas eResource
ca.uhn.fhir.model.dstu2.re source.Ord er
IdDt is inherited from the ca.uhn.fhir.model.api.Base Identifiab leElement as show here:
http://hapifhir.io/apidocs/ca/uhn/fhir/model/primitive/IdDt.html
This is the hierarchy for IdDt:
java.lang.Object
ca.uhn.fhir.model.api.Base Element
ca.uhn.fhir.model.api.Base Identifiab leElement
ca.uhn.fhir.model.api.Base Primitive< String>
ca.uhn.fhir.model.primitiv e.UriDt
ca.uhn.fhir.model.primitiv e.IdDt
public void setId(IdDt theId)
This is the hierarchy for Order:
java.lang.Object
ca.uhn.fhir.model.api.Base
ca.uhn.fhir.model.dstu2.re
ca.uhn.fhir.model.dstu2.re
IdDt is inherited from the ca.uhn.fhir.model.api.Base
http://hapifhir.io/apidocs/ca/uhn/fhir/model/primitive/IdDt.html
This is the hierarchy for IdDt:
java.lang.Object
ca.uhn.fhir.model.api.Base
ca.uhn.fhir.model.api.Base
ca.uhn.fhir.model.api.Base
ca.uhn.fhir.model.primitiv
ca.uhn.fhir.model.primitiv
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Classes werent written by me Im afraid. They are Third Party. Fhir and its java classes is a standard provided by the medical community.
Nevertheless, this is what I could find.
https://github.com/jamesagnew/hapi-fhir/blob/master/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/BaseIdentifiableElement.java
Thanks
Nevertheless, this is what I could find.
https://github.com/jamesagnew/hapi-fhir/blob/master/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/BaseIdentifiableElement.java
Thanks
ASKER
Any help would be appreciated.