V
V
vitya_brodov2021-04-06 22:29:17
Java
vitya_brodov, 2021-04-06 22:29:17

Is it possible to parse a josn file without creating an object of it?

I have json file: people.json
and following code:

Gson gson = new Gson();
        Person person = new Person(); 

        try{
            FileReader fr = new FileReader("/home/xxx/IdeaProjects/hw/src/people.json");
            person = gson.fromJson(fr, Person.class);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

Questions:
1. Is it possible to read and enter a json file without creating an object?
2. If there is an opportunity to use Stream api or lambdas in this code?

Ps I know, the questions are sooooo stupid, but still decided to ask.
Please do not swear

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2021-04-06
@vitya_brodov

1. Well, ok, let's say you somehow parsed your json ... And then what? Do you need to work with this information somehow? And here it turns out that it is most convenient and logical to use a class.
2. Nothing happens here. Streams and lambdas are not needed here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question