0

I'm currently reading in JWK token from a parameter store into a Java properties file. Once it's in the property file I read it form there and get something in this format back.

"{ private: { a: adasdas, b: asdasdasd, c: asdasdas} }"

Is there a way to turn this into a hashMap<string, object> so that I can grab the private object?

1 Answer 1

1

This is not valid json, so ObjectMapper won't be able to parse it.

As a workaround, you could use the following code to preprocess the json string and then parse it:

 ObjectMapper objectMapper = new ObjectMapper();
    String invalidJson ="{ private: { a: adasdas, b: asdasdasd, c: asdasdas} }";
            invalidJson = (invalidJson .replaceAll(":\"?([^{|^]*?)\"?(?=[,|}|\\]])",":\"$1\"").replaceAll("\"?(\\w+)\"?(?=:)","\"$1\""));
            Map<String, Object> theMap = objectMapper.readValue(invalidJson , Map.class);
            System.out.println(theMap.get("private"))
Sign up to request clarification or add additional context in comments.

Comments

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.