Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To be closed as mistake of me #98

Closed
1 task done
nicolasmol opened this issue Sep 15, 2022 · 0 comments
Closed
1 task done

To be closed as mistake of me #98

nicolasmol opened this issue Sep 15, 2022 · 0 comments

Comments

@nicolasmol
Copy link

nicolasmol commented Sep 15, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Running whatever JSON to DART model from Selection or from .json_models folder where I have the following .jsconc

Expected Behavior

Methods from both classes Question & Answer should be implemented but only the top level ones (Question) are:

class Question {
  final String? id;
  final String? title;
  final String? imageUrl;
  final String? description;
  final int? timeSeconds;
  final List<Question>? questions;

  const Question({
    this.id,
    this.title,
    this.imageUrl,
    this.description,
    this.timeSeconds,
    this.questions,
  });

  factory Question.fromJson(Map<String, dynamic> json) => Question(
        id: json['id'] as String?,
        title: json['title'] as String?,
        imageUrl: json['image_url'] as String?,
        description: json['Description'] as String?,
        timeSeconds: json['time_seconds'] as int?,
        questions: (json['questions'] as List<dynamic>?)
            ?.map((e) => Question.fromJson(e as Map<String, dynamic>))
            .toList(),
      );

  Map<String, dynamic> toJson() => {
        'id': id,
        'title': title,
        'image_url': imageUrl,
        'Description': description,
        'time_seconds': timeSeconds,
        'questions': questions?.map((e) => e.toJson()).toList(),
      };

  Question copyWith({
    String? id,
    String? title,
    String? imageUrl,
    String? description,
    int? timeSeconds,
    List<Question>? questions,
  }) {
    return Question(
      id: id ?? this.id,
      title: title ?? this.title,
      imageUrl: imageUrl ?? this.imageUrl,
      description: description ?? this.description,
      timeSeconds: timeSeconds ?? this.timeSeconds,
      questions: questions ?? this.questions,
    );
  }
}
class Answer {
  Answer();

  factory Answer.fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    throw UnimplementedError('Answer.fromJson($json) is not implemented');
  }

  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    throw UnimplementedError();
  }
}

THIS ONE SHOULD BE LIKE :

class Answer {
  final String? answer;
  final String? indentifier;

  const Answer({this.indentifier, this.answer});

  factory Answer.fromJson(Map<String, dynamic> json) => Answer(
        answer: json['answer'] as String?,
        indentifier: json['indentifier'] as String?,
      );

  Map<String, dynamic> toJson() => {
        'answer': answer,
        'indentifier': indentifier,
      };
}

Steps To Reproduce

No response

Version

3.5.8

Relevant JSON syntax

{
  "__className": "question",
  "__path": "/lib/app/data/models/question_paper_model",
  "id": "ppr004",
  "title": "Biology",
  "image_url": "",
  "Description": "Basic Biology Multiple Choice Questions (MCQ) to practice basic Biology quiz answers",
  "time_seconds": 900,
  "questions": [
    {
      "id": "ppr004q001",
      "question": "A relationship in which one animal hunts, kills and eats another",
      "answers": [
        {
          "identifier": "A",
          "Answer": "Symbiosis"
        },
        {
          "identifier": "B",
          "Answer": "Mutualism"
        },
        {
          "identifier": "C",
          "Answer": "Parasitism"
        },
        {
          "identifier": "D",
          "Answer": "Predation"
        }
      ],
      "correct_answer": "D"
    },
    {
      "id": "ppr004q002",
      "question": "The animal that is hunted and killed for food.",
      "answers": [
        {
          "identifier": "A",
          "Answer": "Decomposer"
        },
        {
          "identifier": "B",
          "Answer": "Predator"
        },
        {
          "identifier": "C",
          "Answer": "Scavenger"
        },
        {
          "identifier": "D",
          "Answer": "Prey"
        }
      ],
      "correct_answer": "D"
    },
    {
      "id": "ppr004q003",
      "question": "A close relationship between two different species of organisms living together.",
      "answers": [
        {
          "identifier": "A",
          "Answer": "Mutualism"
        },
        {
          "identifier": "B",
          "Answer": "Symbiosis"
        },
        {
          "identifier": "C",
          "Answer": "Competition"
        },
        {
          "identifier": "D",
          "Answer": "Commensialism"
        }
      ],
      "correct_answer": "B"
    },
    {
      "id": "ppr004q004",
      "question": "A symbiotic relationship in which both species benefit.",
      "answers": [
        {
          "identifier": "A",
          "Answer": "Mutualism"
        },
        {
          "identifier": "B",
          "Answer": "Commensialism"
        },
        {
          "identifier": "C",
          "Answer": "Parasitism"
        },
        {
          "identifier": "D",
          "Answer": "Predation"
        }
      ],
      "correct_answer": "A"
    },
    {
      "id": "ppr004q005",
      "question": "Which organelle is found in most plants, some bacteria and some protists?",
      "answers": [
        {
          "identifier": "A",
          "Answer": "ribosomes"
        },
        {
          "identifier": "B",
          "Answer": "mitochondria"
        },
        {
          "identifier": "C",
          "Answer": "endoplasmic reticulum"
        },
        {
          "identifier": "D",
          "Answer": "chloroplasts"
        }
      ],
      "correct_answer": "D"
    }
  ]
}

Anything else?

No response

@nicolasmol nicolasmol changed the title Question: are nor sub classes' methods supposed to be automatically generated ? Question: are not nested classes methods supposed to be automatically generated ? Sep 15, 2022
@nicolasmol nicolasmol changed the title Question: are not nested classes methods supposed to be automatically generated ? Question: are not nested json's classes methods supposed to be automatically generated ? Sep 15, 2022
@nicolasmol nicolasmol changed the title Question: are not nested json's classes methods supposed to be automatically generated ? To be closed as mistake of me Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant