Need to get Jackson JARS for Jersey - json

I am trying to pass JSON data in a post to a Jersey- based REST service. After getting HTTP 415 errors, I researched and learned that Jersey needs certain Jackson Jars in order to handle JSON.
I have been trying to find the correct Jars, but every link I am finding seems to point to places where there are a lot of README files and XML files but no Jars!
There are also several links provided here on Stack Overflow to Jackson jars. They either don't work, point to links without jars, or point to versions that will not work with Jersey v2.
Worse, I cannot find a consistent list of the Jackson jars needed for Jersey! I keep seeing different lists of Jar files that I cannot find.
Can someone please point me to the correct Jackson jars needed to provide Jersey with JSON processing??? Where can I find and download them?

Just grab all the below Jars.
You can find all of them here. Just search for them individually.
If you are registering your providers individually, regiser
JacksonJaxbJsonProvider for basic JSON/POJO support.
JsonMappingExceptionMapper for an ExceptionMapper for JsonMappingException
JsonParseExceptionMapper for an ExceptionMapper for JsonParseException
Or if you are registering packages to be scanned, add this package
com.fasterxml.jackson.jaxrs.json
Note: The above image is from an older post. Jackson is at 2.6.1 right now. If you want, you can get the newest version. Doesn't make a difference. Just make sure all the jars are the same version

Related

Render HAL formatted links in openapi3 json with SpringDoc

I'm running a Spring Boot REST application with Spring HATEOAS support and generating OpenAPIv3 docs with the Springdoc Maven plugin. However when I call my REST endpoints I get links the in HAL formatted JSON ("_links"). But the generated OpenAPIv3 documentation is giving me a different format for the links ("links").
How can I get the generated OpenAPIv3 docs to match the HAL formatted links?
The only resource I've found is this link: https://github.com/springdoc/springdoc-openapi/issues/446
However, the solution given there involves using spring-data-rest which I am not using (do I need to?)
I've also tried adding #EnableHyperMediaSupport which says it configures the JSON rendering, but that had no effect on the OpenAPIv3 docs.
The answer was simple enough, I needed to pull in the springdoc-openapi-hateoas dependency (https://springdoc.org/#spring-hateoas-support). After pulling this in the JSON documentation was generated correctly with no additional configuration (I did not need #EnableHypermediaSupport or spring-data-rest).
However, if you are using the Swagger UI be aware that it will automatically generate bogus 'additionalProperty' links as an example for the resource schema. This is only in the Swagger UI, if you look at the generated openapiv3 json the structure is correct (cf: https://github.com/springdoc/springdoc-openapi/issues/237). To remedy this you can provide your own example of the resource schema.

Apache Nifi, how to get JSON from API

I've started using Apache Nifi and I'm still learning it and experimenting with it. I really want to use Nifi to get JSON documents from API's and put them in my Elasticsearch database. So far using the built-in getTwitter and putElasticsearch controllers this works.
However now I want to do this with other APIs than Twitter, and I'm kinda stuck here. First off I really don't even know which controller to use? I would think getHttp or invokeHttp even with 'GET' as http verb then but it doesn't seem to work. If I use the getHttp I have to give an SSL service with keystore and truststore .. like why would I have to do that?
Apache Nifi is still quite new so hard to find decent guides / information about these kinds of things. I have read and searched the documentation but haven't gotten the wiser.
An example JSON to pick up from an API is:
https://api.ssllabs.com/api/v2/getEndpointData?host=www.bnpparibasfortis.be&s=193.58.4.82
Thanks in advance for anyone that can offer some help / insight.
What processor you use to get the JSON data is entirely dependent on the API you want to hit. The GetHttp or InvokeHttp processors should work to grab the data from a URL. If you'll notice, the SSL service is an optional property for both GetHttp and InvokeHttp so you only need to you use it when you want to communicate via HTTPS. Also, from the UI you can right click on a processor and then click "usage" to bring up the documentation for that processor.
At this link[1] you can find a NiFi template that uses GetHttp to get JSON data from randomuser.me and does various processing on it. It's primarily a template to show-case the different Avro processors but the method of grabbing the JSON should be relevant.
[1] https://github.com/hortonworks-gallery/nifi-templates/blob/master/templates/Convert_To_Avro_From_CSV_and_JSON.xml

json-lib - how many classes does JSONSerializer require?

I'm trying to parse some JSON data, and I'm using the examples from this site: http://answers.oreilly.com/topic/257-how-to-parse-json-in-java
I'm using the data from section 2 and the code from section 3, and json-lib as my JSON library.
But when I tried to run the sample, the JSONSerializer class about a missing a language class from Apache Commons. I downloaded that, and it complained of a missing logging class. I downloaded that, and it complained of the missing EZmorph class. I downloaded that, and it complained of a missing Collections class. I then downloaded an unofficial JAR file with all the Apache Commons components, and it complained of a missing SLF4J logger or something. At least point, I gave up and decided to try Google's GSON instead.
This seems much more complicated than it should be. Just how many packages do I need do download? Is there a way to disable logging? Or am I doing something wrong?
I would recommend using another, more commonly used Java JSON library: for example Jackson or GSON. There are lots of tutorials and articles on using both, and I don't think there are many reasons to use json-lib over either one.
You can also have a look at Genson.
It is a all in one library, with nice features, easy to use and with good performances.
For example to serialize a full pojo to json and then deserialize it back :
Genson genson = new Genson();
String json = genson.serialize(yourPojo);
// and deserialize it
YourPojo pojo = genson.deserialize(json, YourPojo.class);
As Staxman says, there is no reason to use json-lib. I am still surprised of how many people are using it when there a couple of better libraries.

Axis2 WebServices with JSON objects

I'm trying to get Axis2 WebServices to work with JSON Objects for three days, and can't get it right.
They have to receive and return JSON so it can comunicate with an iPhone app. I've tried everything it the first seven pages in Google and got nothing.
I've already put the Message Formatters and Message Builders in axis2.xml. So as jettison jar in the lib folder.
Can someone help me, please? I need an example of how to make this to work.
Thanks!

Tomcat not using JAXB for JSON marshalling correctly?

I'm working on a RESTful Web-service using Jersey v1.9.1. Some methods return JSON. When I want to Debug my application I start within a grizzly server, otherwise for production I build a war file and place it in a TomCat v7 installation. My projects are all Maven2 projects.
Now, I noticed that for a method that returns List<CustomObj>, where CustomObj has appropriate JAXB annotations, i.e. #XmlRootElement(name="CustomObj"), and getter/setters for all relevant members:
Using grizzly, I get something like {"CustomObj":[{<fields-of-customObj>},{<fields-of-customObj>},{<fields-of-customObj>}]} (when the list has 3 elements). Parsing this with GSON works fine.
Using TomCat, however, I get this: [{<fields-of-customObj>},{<fields-of-customObj>},{<fields-of-customObj>}] -> so as you can see, the "root" is missing somehow
I have the impression that the jersey-json module (which I included into my Maven2 dependencies) are not used at all in TomCat, even though they should be used (they are used in Grizzly for sure). Also, creating my own #Provider for a ContextResolver<JAXBContext> as described here only works in grizzly, in TomCat the getContext() method will never be called.
Is there anything I need to consider with TomCat?
Cheers!