Created
October 17, 2022 09:50
-
-
Save ram0973/3a1213b31d2c1e7fc3c0b26f465c32fe to your computer and use it in GitHub Desktop.
Викторина
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example; | |
import com.fasterxml.jackson.annotation.JsonProperty; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import java.io.File; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.Objects; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
ObjectMapper mapper = new ObjectMapper(); | |
File file = new File(Objects.requireNonNull(TestClass.class.getClassLoader().getResource("test.json")).getFile()); | |
TestClass testClass = mapper.readValue(file, TestClass.class); | |
System.out.println(testClass.questions.get(0)); | |
Answer answer = testClass.answers.get(0); | |
System.out.println(answer.options); | |
} | |
} | |
class Answer { | |
ArrayList<ArrayList<String>> scores; | |
ArrayList<String> options; | |
@JsonProperty("options") | |
public ArrayList<String> getOptions() { | |
return this.options; | |
} | |
public void setOptions(ArrayList<String> options) { | |
this.options = options; | |
} | |
@JsonProperty("scores") | |
public ArrayList<ArrayList<String>> getScores() { | |
return this.scores; | |
} | |
public void setScores(ArrayList<ArrayList<String>> scores) { | |
this.scores = scores; | |
} | |
} | |
class TestClass { | |
ArrayList<String> questions; | |
ArrayList<Answer> answers; | |
ArrayList<String> results; | |
@JsonProperty("questions") | |
public ArrayList<String> getQuestions() { | |
return this.questions; | |
} | |
public void setQuestions(ArrayList<String> questions) { | |
this.questions = questions; | |
} | |
@JsonProperty("answers") | |
public ArrayList<Answer> getAnswers() { | |
return this.answers; | |
} | |
public void setAnswers(ArrayList<Answer> answers) { | |
this.answers = answers; | |
} | |
@JsonProperty("results") | |
public ArrayList<String> getResults() { | |
return this.results; | |
} | |
public void setResults(ArrayList<String> results) { | |
this.results = results; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment