troubleshooting Question

Spring not serializing Fhir Object Despite using @JsonIgnore

Avatar of onaled777
onaled777Flag for United States of America asked on
JavaJava EEJSON
8 Comments1 Solution352 ViewsLast Modified:
This is the error I see when I try to deploy to Jboss:

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();
	}


	
}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros