CXF REST Client Parses Badgefish JSON Data

Badgerfish is one of the JSON conventions supported by CXF. To use it with CXF RS Client, you need to add both cxf-rt-rs-extension-providers and cxf-rt-rs-client to your dependencies. Then you can create a JSON provider and pass it to the web client to make request. The following example calls the D&B Direct API sandbox to retrieve some sample data.

Bean declaration:


@XmlRootElement
public class SampleData{
...
}

Code to map JSON to the bean:


JSONProvider<SampleData> provider = new JSONProvider<>();
provider.setConvention("badgerfish");
//Configure the provider as needed
provider.setSerializeAsArray(true);
provider.setDropRootElement(true);
provider.setUnmarshallAsJaxbElement(true);
provider.setConvertTypesToStrings(true);

WebClient client =
WebClient.create("https://direct.dnb.com", Collections.singletonList(badgerFishJson));
client = client.accept("application/json").path("/V5.0/organizations")
.query("CountryISOAlpha2Code", "US").query("SubjectName", "GORMAN2 MANUFACTURING")
.query("match", true).query("MatchTypeText", "Basic").query("TerritoryName", "CA");
client = client.header("Authorization", "xxxxxx");
SampleData result = client.get(SampleData.class);

Advertisements
This entry was posted in Java and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s