hiranthaR / Json-to-Dart-Model

Json to Dart Model extension can convert JSON objects into Dart data classes. It supports pure Dart class conversion, Flutter-recommended JSON serialization using annotations, Freezed support, Effective Dart:Style, and many more features. Currently, it has more than 135,000 installs.
https://marketplace.visualstudio.com/items?itemName=hirantha.json-to-dart
MIT License
93 stars 17 forks source link

Target folder persists to be incorrect #99

Open nicolasmol opened 2 years ago

nicolasmol commented 2 years ago

Is there an existing issue for this?

Current Behavior

Defining my target folder like this image However persists to generate into /lib/data image

Expected Behavior

No response

Steps To Reproduce

No response

Version

No response

Relevant JSON syntax

{
  "__className": "biology",
  "Description": "Basic Biology Multiple Choice Questions (MCQ) to practice basic Biology quiz answers",
  "id": "ppr004",
  "image_url": "",
  "questions": [
    {
      "__className": "question",
      "answers": [
        {
          "__className": "answer",
          "Answer": "Symbiosis",
          "identifier": "A"
        },
        {
          "__className": "answer",
          "Answer": "Mutualism",
          "identifier": "B"
        },
        {
          "__className": "answer",
          "Answer": "Parasitism",
          "identifier": "C"
        },
        {
          "__className": "answer",
          "Answer": "Predation",
          "identifier": "D"
        }
      ],
      "correct_answer": "D",
      "id": "ppr004q001",
      "question": "A relationship in which one animal hunts, kills and eats another"
    }
  ],
  "time_seconds": 900,
  "title": "Biology"
}

Anything else?

No response

iamarnas commented 2 years ago

@nicolasmol Hi 👋 First, I see your JSON is not valid for this generator. JSON body is an unnamed object and therefore we need to add a class name to avoid typing it manually. So for each JSON body, you just need to add a __className and __path on the top JSON body. The rest objects will be named depending on the keys.

Example:

{
  "__className": "biology", // <- classname and path only paste here at the top of the body.
  "Description": "Basic Biology Multiple Choice Questions (MCQ) to practice basic Biology quiz answers",
  "id": "ppr004",
  "image_url": "",
  "questions": [ // <- this key is a class name and you don't need to add it manually.
    {
      "__className": "question", // <- remove this, generator handle it automatically.
      "answers": [ // <- here is a class name for list members.
        {
          "__className": "answer",  // <- don't do that, that's why you Answer class is not implemented. The generator already knows that this object is Answer object due to the list keeper key name.
          "Answer": "Symbiosis",
          "identifier": "A"
        }
      ],
      "correct_answer": "D",
      "id": "ppr004q001",
      "question": "A relationship in which one animal hunts, kills and eats another"
    }
  ],
  "time_seconds": 900,
  "title": "Biology"
}

This is how your JSON should look:

{
  "__className": "biology",
  "Description": "Basic Biology Multiple Choice Questions (MCQ) to practice basic Biology quiz answers",
  "id": "ppr004",
  "image_url": "",
  "questions": [
    {
      "answers": [ 
        {
          "Answer": "Symbiosis",
          "identifier": "A"
        }
      ],
      "correct_answer": "D",
      "id": "ppr004q001",
      "question": "A relationship in which one animal hunts, kills and eats another"
    }
  ],
  "time_seconds": 900,
  "title": "Biology"
}