org.openmrs.module.webservices.rest.web.response.ConversionException

Tags: #<Tag:0x00007f79075ec388>

I try to create/save a LabTestAttribute it throws a ConversionException exception. I am writing a unit test for one of our module named as common lab test module. Before going on the issue I will let know the structure of module code.

Entity https://pastebin.com/ZGH2Tf18

ResourceController https://pastebin.com/8LQSgbRj

Test Case https://pastebin.com/vb3ijaEK

Hibernate File https://pastebin.com/mgh5az5M

Exceptions https://pastebin.com/sFBiFdCa

@shujaat, there is probably missing a @PropertyGetter annotated method for the property valueReference that you added. You may need to provide this method depending on your use case to silence this error.

@ruhanga, in openmrs BaseAttribute class we have the setter and getter for valueReference property, Take a look at the BaseAttribute Abstract Class https://pastebin.com/x48RTGi0.

Is this the full stack trace?

Yes @dkayiwa !

Can you commit your changes to a repository from where we can check out?

please checkout the master branch https://github.com/seekme94/openmrs-module-commonlabtest

Can you add these to the resource? https://pastebin.com/MaKaehPG

1 Like

Okay, let me add this @PropertyGetter /@PropertySetter for value.

Thanks a bunch @dkayiwa, these methods as is didn’t work, but I got the point. We needed to explicitly define PropertyGetter/Setter to handle value in this case.

@shujaat please check this commit…

I encountered the same error but with class org.openmrs.module.webservices.helper.TaskAction

at org.openmrs.module.webservices.rest.web.response.ConversionException: tasks on c - Pastebin.com

but slightly different case

PR at RESTWS-764 by tendomart · Pull Request #475 · openmrs/openmrs-module-webservices.rest · GitHub

Anyone have an idea ?

@tendomart did you take a look at this in your log?

Caused by: java.lang.NumberFormatException: For input string: "TestTask" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.parseInt(Integer.java:615) at org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.TaskDefinitionResource1_8.getByUniqueId(TaskDefinitionResource1_8.java:119)

@dkayiwa Yes I did , am not however certain why it throws a NumberFormatException yet i did provide the right params for this constructor TaskDefinition(java.lang.Integer id, java.lang.String name, java.lang.String description, java.lang.String taskClass)

@tendomart in your test, getUuid() returns getTestTaskName() which is TestTask, hence causing the error.

@dkayiwa was > @Override

    public String getUuid() {
        return RestTestConstants1_8.TASK_DEFINITION_UUID;
    } 

Necessarily designed to take in a string , if so then why do we have to parse in Non-Numeric **RestTestConstantsX_.UUID’**s then again type cast them to integers ?

I asked because trying to return a uuid as above a String , still requires an int , and failure to do so throws

java.lang.NumberFormatException: For input string: “266a2ff1-f0b1-45f4-ad04-2ce952a27920”

You need to override the TaskDefinitionResource1_8.getByUniqueId() method and deal with the uuid.

Thanks, Let me explore that .

I did it but am still getting a String to Int Casting Error specifically java.lang.NumberFormatException

something like this java.lang.NumberFormatException: For input string: “0464edb8-4a6e-11eb-b378-0242ac130002” so that we can not return the TaskDefinition using a the provided String uuid , as per the requirement.

@dkayiwa looks like we need to provide OverLoad TaskDefinition in core to accept an Int .

something like

TaskDefinition.getTaskById(String st)

with something like

TaskDefinition.getTaskById(Int in)

in core

Can you share the change you made to override getByUniqueId?

Wrapper getUUid Method

public class TaskServiceWrapper2_4 extends TaskServiceWrapper {

public TaskDefinition getTaskByUuid(String uuid) {
	return Context.getSchedulerService().getTaskByUuid(uuid);
}

}

Wrapper method injected at

public class TaskDefinitionResource2_4 extends TaskDefinitionResource1_8 {

 private TaskServiceWrapper2_4 taskServiceWrapper = new TaskServiceWrapper2_4();

    public void setTaskServiceWrapper(TaskServiceWrapper2_4 taskServiceWrapper) {
        this.taskServiceWrapper = taskServiceWrapper;
    }

.......
}

This is how the change looks like.

@Override
        public TaskDefinition getByUniqueId(String uniqueId) {
            TaskDefinition taskDefinition = taskServiceWrapper.getTaskByUuid(uniqueId);
            if (taskDefinition == null) {
                taskDefinition = taskServiceWrapper.getTaskById(Integer.parseInt(uniqueId));
            }
            return taskDefinition;
        }