Add a dynamically generated field in a REST CustomRepresentation

Hi,

I have written my own ConceptResource that’s supposed to return a dynamically generated field.

I override the getRepresentationDescription fn and add:

description.addProperty("value", findMethod("getConceptNameValue"));

How can I include such a field when setting my custom representation? I have tried v=custom:(uuid,name,value) and it doesn’t work - maybe because there is no value field in a concept entity?

Thanks

Andrew

Can you share full code of your ConceptResource?

ConceptResource.txt (1.3 KB)

From the code in the attached file you’re returning null for the CustomRepresentation, meaning it defaults to whatever the framework has to do which also implies your other lines of code that add the value property to the representation description never get executed anyways.

The other thing is, after a quick glance at the framework code it appears like resource descriptions for custom representations are generated on the fly and I doubt if it takes care of findMethods since in the json there is no way to tell it what is a field vs a find method as you would do in the getRepresentationDescription() method.

Ok, thanks

Can we then conclusively say that a custom representation doesn’t allow one to reference a custom/dynamic field?

I will let @raff confirm that because I think he wrote that code and might have a better response

Ok, thanks

Actually that’s not true.

The “findMethod” approach does not work with custom representations, for the reason Wyclif found. However there’s an easy alternative, which is to annotate your method with @PropertyGetter. See here for more details:

https://issues.openmrs.org/browse/RESTWS-421

1 Like

Thanks @darius. Works as expected!