How to read JSON data from the URL in XPage Java Bean


I get that typically this is something better done with Client Side JavaScript. However CSJS is not ideal in this situation for other reasons.

BUT if I have a Java object inside XPages. A managed bean maybe or whatever. Is it possible to read in JSON information to the object for parsing purposes? In theory I'd want to process the data and use it in a TypeAhead for an editbox control.

The reason I'm interested in this rather then using the more tradition domino object model is the speed of getting the entries. I'm wondering if a view thats using the great "startkey" parameter is faster then something like getAllEntriesByKey().

For instance this view:

To to sum up I'm look to see if it's possible to injest the data from that link into a Java Object from XPages. the key could be anything... doesn't have to be "Fav".

Thank you!

There are 2 parts to the question:

  1. How to read data from an URL. Here Oliver provided the hint: use the Apache HTTP client (the libraries are in XPages)
  2. How to turn that JSON into a Java object. Here I would use Google GSON and a matching object. The Apache HTTP client gives you access to an input stream for the body. Something like

    SomeClass createFromJson(InputStream in) { Gson gson = new GsonBuilder().create(); SomeClass sc = gson.fromJson(in, SomeClass.class); return sc; }