Вопрос

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top