RESTBuilder TransformUtil Errors

I keep running into this, solving and forgetting about it, then running into it again and have to figure it out again. So now I'm blogging the solution so I don't have to figure it out again...

Just a short one today...

So like every few months I either encounter a build error from RESTBuilder code, or someone asks me about it...

Basically after generating RESTBuilder code, when you try to build, you hit an error like:

BaseEventEntryResourceImpl.java:274: error: no suitable method found for 
  transform(T#1[],UnsafeFunction<T#1,R#1,Exception>,Class<CAP#1>)
        return TransformUtil.transform(array, unsafeFunction, clazz);
                            ^

So there's actually a couple of things that you should do, but one thing you must do to get by the issue...

First, in your settings.gradle, you should be using a recent version of the workspace plugin. If you have an older version, you could be using older versions of other plugins.

Second, in your rest-config.yaml file, you should specify a compatibilityVersion. Add / edit a line in the file to read:

compatibilityVersion: 6

What is compatibilityVersion?

It is used to change the generated RESTBuilder code, sometimes in simple ways (i.e. how a name is pluralized), sometimes in complex ways (compatibilityVersion 4 along with a merge property setting enables merging in all reference schema properties into your local schema).

To get a full list of the versions and their impact, and since they're not documented, if you search the Liferay source for isVersionCompatible you'll find all of the values used and the wrapped code that is included when the version is compatible.

Note that the check is greater than or equal to, so with compatibilityVersion of 6, you get a true result for a test of 4 but false on a test for 8.

Finally, and this one is the critical point, you can manually choose the version of the RESTBuilder plugin to use when generating code.

In the -impl folder (where your rest-config.yaml file is), add a gradle.properties file and put the following line in it:

com.liferay.portal.tools.rest.builder.version=1.0.338

That last one, that's the thing that you have to do to be successful.

After making the change, re-run RESTBuilder to regenerate the code and now your build error should be gone...

If this doesn't solve your issue, leave a comment below or hit me up on the Liferay Community Slack!