Unified API with Java

I’m using swagger-codegen-maven-plugin 2.4.5 under Java 8 to build a client library. Whilst it generates classes fine, making an API call to /Line/Mode/{mode}/Status fails, because the autogenerated code is calling /Line/Mode/%5Btube,%20dlr%5D/Status?detail=true, rather than /Line/Model/tube,dlr/Status?detail=true. The lineStatusByMode method call in LineApi requires a List of Strings (and I’m passing an ArrayList) and a Boolean, and it looks like it’s simply doing .toString() on the List.

Can anyone help? Whilst I could hack around this by editing autogenerated code, I’d rather not!

Does this help? You seem to have got some square brackets encoded, rather than just the single word tube

That’s the effect of calling .toString() on a List in Java - “[foo, bar]” rather than what I think swagger-codegen expects - and what the Unified API wants, which is “foo,bar”.

Ruby does similar:

2.5.1 :001 > a = ['foo', 'bar']
 => ["foo", "bar"] 
2.5.1 :002 > a
 => ["foo", "bar"] 
2.5.1 :003 > a.to_s
 => "[\"foo\", \"bar\"]" 

I’m going to try generating the same code in different languages to see if it’s a Java-specific issue or not.

Why can’t you just use a fixed string to call for all the modes? It’s not like it returning that much data.

The autogenerated method requires a List, and won’t let me supply a String. If I dispense with the autogenerated code, I have another problem of deserializing the returned objects in to domain objects.

As far as I’m aware, the “$type” key in the returned JSON is a Microsoft-specific thing, and I don’t want to get wrapped up in writing my own deserialization code

Yes, you can just ignore the “$type” elements, they are not necessary.

The online docs I can see do this kind of thing

JSONParser parser = new JSONParser();
Reader reader = new FileReader("data.json");
Object jsonObj = parser.parse(reader);
JSONObject jsonObject = (JSONObject) jsonObj;

to take some JSON input and tranlsate it to an JSONObject that you can then itterate through?