Avatar of onaled777
onaled777
Flag for United States of America asked on

Spring not serializing Fhir Object Despite using @JsonIgnore

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)"}}

Open in new window




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

Open in new window



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;

}

Open in new window



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>

Open in new window



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


	
}

Open in new window

JavaJava EEJSON

Avatar of undefined
Last Comment
onaled777

8/22/2022 - Mon
gurpsbassi

Could you post the error again, using word wrap? Too hard to see on single line.
onaled777

ASKER
Here you go:

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)"}}
Please choose a file that you want to deploy.
onaled777

ASKER
These are the docs for the ca.uhn.fhir.model.dstu2.resource.Order object:

http://hapifhir.io/apidocs-dstu2/index.html?ca/uhn/fhir/model/dstu2/resource/class-use/Order.html
Your help has saved me hundreds of hours of internet surfing.
fblack61
gurpsbassi

I'd like to see ca.uhn.fhir.model.api.BaseIdentifiableElement and how it is related to the other class.
onaled777

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.BaseElement
ca.uhn.fhir.model.dstu2.resource.BaseResource
ca.uhn.fhir.model.dstu2.resource.Order


IdDt is inherited from the ca.uhn.fhir.model.api.BaseIdentifiableElement  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.BaseElement
ca.uhn.fhir.model.api.BaseIdentifiableElement
ca.uhn.fhir.model.api.BasePrimitive<String>
ca.uhn.fhir.model.primitive.UriDt
ca.uhn.fhir.model.primitive.IdDt
ASKER CERTIFIED SOLUTION
gurpsbassi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
onaled777

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
onaled777

ASKER
Any help would be appreciated.