REST Client Code Generated by NetBeans Does Not Handle Lists and the Solution

In my Introduction to Java Web Services course I use as an example a web service that returns a List of JPA entity objects of type Fish. A Fish is just several fields that describes different aspects of aquarium fish. For many years, going back to 2004, I only showed SOAP services. The code generator in my favourite IDE, NetBeans, output working server and client code. Then about five years ago I added REST services to my curriculum.

The NetBeans code generator for REST services produced workable code except in one situation for REST clients. The List type could not be returned by the generated code. Here is what the client generated code looks like:

public <T> T getJson(Class<T> responseType) throws ClientErrorException {
    WebTarget resource = webTarget;
    return resource.request(;
REST client method

To call this code I used:

List<Fish> fishies = client.getJson(List.class);
Calling the REST service

When I ran this code, I received the following error message:

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/json, type=interface java.util.List, genericType=interface java.util.List.
Error message

This error has been around from the first time I explored REST services. After spending a few hours looking for a solution five years ago I came across one that showed by adding a dependency to my pom.xml the code will work.

Maven dependency

Genson, a Java and Scala JSON conversion library, was created to deal with several issues in REST services, one of which was to simplify working with List. You can learn more about this library at I added the dependency to the client pom file and never gave it another thought until today. How could jax-rs not be able to handle a List? So, I did more research.

I discovered that this was a problem that many had encountered and not just NetBeans users. There were several suggested solutions, but the one that made the most sense showed me that the problem was not with jax-rs but with the code that NetBeans generated.

The solution came from Adam Bien’s blog. Adam is one of the foremost Java EE developers and trainers who is in great demand as a speaker. I have had the good fortune of meeting him at JavaOne. His blog at showed that responses from a REST service that are in a List must be wrapped in a GenericType class. First, I changed the generated getJson method, renaming it getJson2:

public List<Fish> getJson2() throws ClientErrorException {
    WebTarget resource = webTarget;
    return resource.request(
        .get(new GenericType<List<Fish>>() { });
Corrected method for returning a List

If you compare this to the generated code shown earlier in this article you will see that this method is now tightly coupled to the data type it is returning. The generated code was designed to work in all cases because it used generics. As generated, you needed to pass the class of the returned data. Problem is that you cannot pass a generic type such as List<Fish>.class instead of List.class.

When the return type is a generic collection, Adam pointed out that it must be wrapped in a GenericType class that is part of jax-rs. The code that NetBeans produces should work in all cases but not in this case.

The dependency for Genson is now removed and my executable client is 378K smaller.

Thanks to Adam Bien for his article. Read his blog at and follow him on Twitter at @AdamBien

Raspberry Pi, Java, and the GoPiGo3 – Part 1: Setting up the GoPiGo3

The following article assumes that you have successfully assembled the GoPiGo3 robot car from Dexter Industries. I found the assembly instructions well written and the parts are quite sturdy. I expected this considering that the GoPiGo3 is aimed at the education market rather than the hobbyist and to have a product that children will work with needs to be sturdy. Having said that, I believe the GoPiGo3 is an ideal platform for the hobbyist and anyone interested in robotics and IoT. Kudos to the engineers at Dexter Industries. You can learn more about the GoPiGo3 by visiting

The GoPiGo3 parts on the dining room table.

The wheels and their motor.

The Raspberry Pi is attached.

Completed with the Grove GoPiGo3 board attached on top of the Pi.

The Raspberry Pi that I am using in the car is a Pi 3 model B. This version of the Pi has WiFi built in so an external WiFi dongle is not required. The completed unit needs 12 volts to power it rather than the Pi’s usual 5 volts. The extra voltage is for the electric motors. You are expected to use 8 AA batteries. Rather than use disposable batteries I ordered an 8 pack of rechargeable batteries and an 8-slot charger from Amazon. I chose batteries that had the highest milliamp rating, 2800 mA. Rechargeable batteries are 1.25 volts so the total voltage is 10 rather than 12 volts but the car runs without any problem.

Dexter provides two different OS images that you can use. The first is DexterOS. This OS does not require you to interact with the Raspberry Pi such as adding a keyboard, mouse and monitor. When the Pi boots up it is a wi-fi hotspot that you can connect your computer, tablet or any other device that has a web browser. Once you connect to the Pi’s wi-fi you open your browser and go to

The DexterOS web page.

You can now carry on a number of tasks with the car. I was just interested in verifying that it works so I chose Drive from the web page. The page that came up presented buttons to move the car forward or backwards, turn left or right, and stop. Here is a short video of my car driving.

There are two ways to code the car using DexterOS, both with a web interface. My goal is to use Java so DexterOS was not suitable. Instead I switched to Dexter’s version of Raspbian for Robots.

Raspbian for Robots is a full-fledged, for a Pi, Linux distribution. Initially you will need to connect a keyboard, mouse and monitor to configure the Pi. Once complete you can manage the Pi remotely and no longer need the keyboard, mouse and monitor.

When you start your Pi with Raspbian for Robots you will be presented with a GUI desktop. The desktop image below is not the same as what you will see as this is what it looks like after the operating system is updated.

GoPiGo3’s Raspberry Pi up and running.

When your desktop comes up on your monitor the first thing to do is to run WiFi Setup that you will find on the desktop. You can now connect the Pi to your home wi-fi. Take note of the IP number your router will give your Pi. You will need this to connect remotely to the Pi. Verify that the setup is successful by opening the Pi’s browser and enter in a URL. I recommend For more details on configuring the wi-fi read

Now you can carry out the operating system update. On the desktop you will find DI Software Update. Run this and after a few minutes your Pi will be updated with the latest version of Raspbian plus updates to the Dexter software.

Here are some strongly recommended configuration tasks that you should carry out.

Raspbian Preferences.

Clicking on the Raspberry Pi logo in the upper left corner will display a menu. Select Preferences and on the next menu select Raspberry Pi configuration. You will now see the following.

System configuration.

The first thing to do is change the password. By default the user name is ‘pi’ and the password is ‘robots1234’. As your robot will on a wi-fi network you should change the password.

The default Hostname is ‘dex’. Its not necessary to change it but I do to personalize my Pi on the network.

I uncheck Auto login: Login as user ‘pi’. Rarely should a system log in itself.

Change the Boot to CLI rather than Desktop. I do this because I will be accessing the Pi remotely and I don’t need the Pi to execute a desktop that will not be seen. The goal of this project is to control the car from either a web page or a web service in Java so a desktop is not required.

The only other configuration you may inspect and change is Localization. Here is where you can provide information on where you are in the world, your time zone, your keyboard type, and the wi-fi country.

Localization configuration.

You can verify the operation of the car by running the GoPiGo3 Control Panel that you will find on the desktop. Like with the DexterOS web interface, this program, that I believe is written in Python, will let you move the car forward, backwards, let, right and stop. It should work.

GoPiGo3 Control Panel

There is one last step in this setup. As we do not want to leave the keyboard, mouse, and monitor connected to the card we need to use a remote desktop tool. Normally the standard application is VNC. This is the choice if your development system is Linux or Mac based. It will also work fine with Windows. See for information on setting it up.

I prefer Windows 10 for my development environment. I could use a VNC client in Windows but I prefer to use the Windows Remote Desktop (RDP) application. To do this you need a Microsoft compatible Remote Desktop server on the Pi. I recommend xrdp. It works flawlessly and does not require additional software on your dev machine. Even when I use a Mac I load up Microsoft’s Remote Desktop client for the Mac rather than use VNC. This is not a slight to VNC. Rather, as I use RDP to access multiple Windows systems I do not want to use a different client for Linux based systems. You can find the instructions to install xrdp at The instruction to open the firewall for port 3389 does not work but the port is open.

Now you are ready for the first test. With the Pi still connected to the keyboard, mouse and monitor go to your Window computer, open the RDP client, enter the IP number of your Pi, and click on Connect. A window should open asking you for your user name and password.

xrdp login.

If all has gone well you should see the Raspbian desktop on your computer.

The Raspbian Desktop.

Now, shutdown the Pi. Remove the keyboard, mouse, and monitor from the Pi. Turn on the Pi. After about a minute open your Remote Desktop client on your Windows computer and connect to the Pi. If you see a desktop similar to the image above then you are ready to start coding for the GoPiGo3.

I’d like to thank John Cole and Dexter Industries for supplying me with the GoPiGo3 Basic kit. The goal is to return Java to first class language status for GrovePi and GoPiGo3 software development.