0

I tried getting json object using jackson but getting exception like this:

SEVERE: Servlet.service() for servlet [JsonProcessor] in context with path [/JJS2] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonGenerator.setCurrentValue(Ljava/lang/Object;)V

Here is the java code:

protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        JSONObject jsonResponse = new JSONObject();
         List<Map<String, Object>> result = new ArrayList<>();// JDK7++

        try {
            JSONArray data = new JSONArray();
            Connection con = OracleDBConnection.getConnection();
            String query = "Select * from JJS";
            Statement st = con.createStatement();
            ResultSet rSet = st.executeQuery(query);

            while (rSet.next()) {
                Map<String, Object> row = new HashMap<>();
                row.put("JSON_Diagram", rSet.getString("JSON_INFO"));
                result.add(row);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        ObjectMapper mapper = new ObjectMapper();
        try {
            response.getWriter().write(mapper.writeValueAsString(result));
            response.getWriter().flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Here's the json sample in database:

{"cells":
[{"type":"basic.Rect","position":{"x":-2,"y":33},
 "size":{"width":71,"height":625},"angle":0,"isInteractive":false,
 "id":"a55845b6-b753-42f0-b361-f0fcd3eaa611","z":1,
 "attrs":{"rect":{"fill":"#EEEEEE","stroke":"#008B8B","stroke-width":2},
".":{"magnet":false}}}

The database has only one column with json data.

1
  • 3
    Provide complete stack trace. But it seems to me like a library version conflict in the webapp. Commented Aug 3, 2015 at 12:02

1 Answer 1

1

You have a version incompatibility between jackson-core (streaming, low-level encoder/decoder) and jackson-databind (object mapping). Most likely you have 2.6 of jackson-databind, but some earlier version of jackson-core. Minor versions of these components must match; or at very least jackson-databind minor version can not be later that jackson-core version.

Sign up to request clarification or add additional context in comments.

1 Comment

fixed it by removing jackson jar. I had two versions by mistake

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.