I found many things about converting Groovy to JSON, but oddly enough, not the other way.
What is the (best) JSON to Groovy parser around there ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because compiled Groovy classes are compatible with Java classes, you should be able to use any Java library for converting JSON to POJOs (or POGOs). Jackson is a fairly popular choice which you can use to convert JSON like this:
to a Map using:
Or if you want to convert the JSON to a Groovy User class:
This will map properties in the Groovy class to keys in the JSON.
In the code above,
mapperis an instance ofcom.fasterxml.jackson.databind.ObjectMapperfrom the Jackson library.