Jackson JSON Mapping "NoClassDefFoundError: JsonPropertyDescription" - java

I am using the Jackson jars (core 2.3.1, annotations 2.2.3, databind 2.3.1, all the latest from the downloads page) to read a Json file, grab what I need put it into a new object and write/printout that object to a file or the screen.
I have seen most examples say that it's as easy as
ObjectMapper mapper = new ObjectMapper();
mapper.writeValueAsString(object);
Or
ObjectWriter mapper = new ObjectMapper().writer().withDefaultPrettyPrinter();
writer.writeValueAsString(object);
Although I have the necessary jar's I keep getting the error
ClassNotFoundException: com.fasterxml.jackson.annotation.JsonPropertyDescription.
Upon digging deeper I find that the JsonPropertyDescription class that is in the github for jackson, is not packaged with the annotations 2.2.3 jar.
So has it been deprecated and there is some new way I haven't seen to take an object and print it to json, or was this class accidentally left out of the newer version?

Not sure if you've solved this already by updating your jars but here go some answers:
Upon digging deeper I find that the JsonPropertyDescription class that is in the github for jackson, is not packaged with the annotations 2.2.3 jar.
It's a new feature in 2.3.
Is there some new way I haven't seen to take an object and print it to json?
I don't think so: writeValueAsString() 2.3.3 (it's not deprecated).
It looks like someone had a similar problem and the solution they suggested is basically "update your jars". The asker didn't reply so we don't know whether that worked or not.

Related

Adding dependencies in Hackerrank

I was solving a question on Hackerrank where I had to hit an API which was returning Json, then I had to map into Object. I had used Libraries like Gson and ObjectMapper to solve the question but the Hackerank IDE was not able to resolve Gson and ObjectMapper libraries even after adding gson and Object mapper libraries in import section. Is there any way to add dependencies in Hackerrank IDE and successfully submit it?
According to the HackerRank Environment documentation, the following libraries are available:
TestNG, JSON Simple, Tagsoup, Google/Gson, HTTPCore, HTTPClient, XMLResolver, Jing, JUnit, Hamcrest, Commons Lang3, Commons Logging.
Source: https://support.hackerrank.com/hc/en-us/articles/1500002392722-Execution-Environment. (Click on "Coding and Database" and scroll to the Java information ...)
Well, you are not allowed to use libraries or frameworks in these challenges. The idea is to check how you would solve the problem, not the developer of a library. That's why these lessons are so challenging. Back to the roots: Use just the Java API itself to pass!

Kotlin-Android serialize json without using third party library

is there any solution other than Moshi, Gson, KotlinX-Serialization to serialize json in Android? We should not add anything to build.gradle while using technology. We should not download a library from here.
Is there a method on Android just like Codable on iOS? Also, I think how we should do this part is important since Converter will be passed when using it with Retrofit.
Does anyone have experience and advice on this subject?
You can use JSONObject for that.
val json = JSONObject("""{"some":"json"}""")
However, easiest is to use one of the third party frameworks you mentioned to do this.

What is Jackson stands for - in many jar in java world?

Jackson is an author name or an organization name? Or does it mean something else.
For example, I am using following jars. I would like to understand the reason for the name, ownership and relationship between these jars.
jackson-mapper-asl-1.9.8.jar
jackson-core-asl-1.9.8.jar
jackson-core-2.9.0.jar
jackson-databind-2.9.0.jar
jackson-annotations-2.9.0.jar
Jackson is a JSON processor for Java POJOs to convert from/to JSON.
These Jars will have annotations to do the work related JSON operations.

json schema to pojo generator

what is the best json to pojo generator which have oneof/allof/anyof features . We are currently using a custom one which doesn't support the latest additions in the json. I have tried some of them that shows in the google search but didn't work.
I use https://github.com/java-json-tools/json-schema-validator for schema validation and jackson for pojo-generator.
However, I did not find any support for allOf/AnyOf/oneOf explicitly in jackson. But jackson has a rich set of annotation and it can be built using those.
you can refer a discussion https://github.com/joelittlejohn/jsonschema2pojo/issues/392 to see if something helpful is there for you.

How to use mapper attachment plugin with JAVA API in elasticsearch

I had executed basic program of indexing and searching with JAVA API in elasticsearch.
Now I want to index the doc, pdf, pptx file for that purpose I need to include Mapper Attachment plugin. For using mapper Attachment plugin with JAVA API I am looking for tutorial or sample program.
Thank you for contribution.
Basically, just add mapper jar to your classpath and when you will start a node, it will be picked up.
Have a look at what we did in scrutmydocs project. It's somehow what you are trying to do.

Categories