Search code examples
javafasterxml

Unable to readvalue from html string using objectmapper


public void testJson() {

        ObjectMapper mapper = new ObjectMapper();
        try {
            String htmlString = mapper.readValue("<!Doctype>", String.class);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: (String)"";

How to fix this issue?


Solution

  • I ended up using gson.

    JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();