D
D
Dik_Nik2019-07-05 16:59:12
Java
Dik_Nik, 2019-07-05 16:59:12

How to parse Json in Java?

I am using jackson databind object.
I get the following Json:

{mode=, hdfsPath=, firstRowAsHeader=false, columns=[], totalRows=null}

I'm trying to parse it using the objectMapper.readTree(json) method, but due to the fact that json is not standard, an Exception is thrown:
Unexpected character ('=' (code 61)): was expecting a colon to separate field name and value
 at [Source: (String)"..."]

The following configurations are currently applied to the object: ALLOW_UNQUOTED_FIELD_NAMES (true); (FAIL_ON_UNKNOWN_PROPERTIES (false).
What other configuration needs to be added to make it work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2019-07-05
@Dik_Nik

It's not json at all. So I doubt that the json parser will be able to parse this with any settings.

B
BorLaze, 2019-07-06
@BorLaze

As noted above, this is not JSON; if memory serves me, this is the result of map.toString().
To get JSON, you need to use ObjectMapper:

String json = objectMapper.writeValueAsString(map);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question