#Import many object JSON in Java

1 messages · Page 1 of 1 (latest)

mortal tendon
#

Hello, i try to search if anyone ask it but i didn't understand any documentation :/
So my question is this : I have a file with some object on a JSON file and i want to import it to create object on an object list. How can I import it ?
I think I've made a bad start to my program, but here it is :

import java.util.ArrayList;


class Application{
    public static void main(){
        ArrayList<Cases> listOfCase;
        
    }
}

class Cases {
    int idCase;
    String nom;
    int whoOwn = 0; // Player id who own the propriety. -1 if not buyable
    int price; // Price of the case
    ArrayList<Integer> playerOnCase = new ArrayList<>();
    boolean isMortgaged = false;
    boolean canBuyHouse = false;
    int color;
    int effect; // 0 nothin | 1 jail | 2 special card | 3 pay
    ArrayList<Integer> loyer = new ArrayList<>(); // loyer[nbHouse] : price need to pay to a player
    int nbHouse = 0; // 0-5 for houses, 5th is an hotel

    public Cases(int idCase, String nom, int whoOwn, int price, ArrayList<Integer> playerOnCase,
                boolean isMortgaged, boolean canBuyHouse, int color, int effect, ArrayList<Integer> loyer, int nbHouse) {
        this.idCase = idCase;
        this.nom = nom;
        this.whoOwn = whoOwn;
        this.price = price;
        this.playerOnCase = playerOnCase;
        this.isMortgaged = isMortgaged;
        this.canBuyHouse = canBuyHouse;
        this.color = color;
        this.effect = effect;
        this.loyer = loyer;
        this.nbHouse = nbHouse;
    }
}
slate lintelBOT
# mortal tendon Hello, i try to search if anyone ask it but i didn't understand any documentatio...

Detected code, here are some useful tools:

Formatted code
import java.util.ArrayList;

class Application {
  public static void main() {
    ArrayList<Cases> listOfCase;
  }
}
class Cases {
  int idCase;
  String nom;
  int whoOwn = 0;
  // Player id who own the propriety. -1 if not buyable
  int price;
  // Price of the case
  ArrayList<Integer> playerOnCase = new ArrayList<>();
  boolean isMortgaged = false;
  boolean canBuyHouse = false;
  int color;
  int effect;
  // 0 nothin | 1 jail | 2 special card | 3 pay
  ArrayList<Integer> loyer = new ArrayList<>();
  // loyer[nbHouse] : price need to pay to a player
  int nbHouse = 0;
  // 0-5 for houses, 5th is an hotel
  public Cases(int idCase, String nom, int whoOwn, int price, ArrayList<Integer> playerOnCase, boolean isMortgaged, boolean canBuyHouse, int color, int effect, ArrayList<Integer> loyer, int nbHouse) {
    this .idCase = idCase;
    this .nom = nom;
    this .whoOwn = whoOwn;
    this .price = price;
    this .playerOnCase = playerOnCase;
    this .isMortgaged = isMortgaged;
    this .canBuyHouse = canBuyHouse;
    this .color = color;
    this .effect = effect;
    this .loyer = loyer;
    this .nbHouse = nbHouse;
  }
}
#

<@&987246399047479336> please have a look, thanks.

mortal tendon
#

and my json file look like this :

[{
    "idCase": 0,
    "name": "Case départ",
    "whoOwn": 0,
    "price" : 0,
    "playerOnCase": [],
    
    "isMorgaged": false,
    "canBuyHouse": false,
    "color": 0,
    "effect": 0,
    "loyer": [],
    "nbHouse": 0
},{
    "idCase": 1,
    "name": "Place de la République",
    "whoOwn": 0,
    "price" : 60,
    "playerOnCase": [],
    
    "isMorgaged": false,
    "canBuyHouse": false,
    "color": 2,
    "effect": 0,
    "loyer": [2,10,30,90,160,250],
    "nbHouse": 0
},...]```
slate lintelBOT
# mortal tendon and my json file look like this : ```json [{ "idCase": 0, "name": "Case...

Detected code, here are some useful tools:

Formatted code
[{
  "idCase" : 0, "name" : "Case départ", "whoOwn" : 0, "price" : 0, "playerOnCase" : [] , "isMorgaged" : false, "canBuyHouse" : false, "color" : 0, "effect" : 0, "loyer" : [] , "nbHouse" : 0}
, {
  "idCase" : 1, "name" : "Place de la République", "whoOwn" : 0, "price" : 60, "playerOnCase" : [] , "isMorgaged" : false, "canBuyHouse" : false, "color" : 2, "effect" : 0, "loyer" : [2, 10, 30, 90, 160, 250] , "nbHouse" : 0}
, ...]
elder verge
#

there are librarys for JSON, like Jackson, Gson, org.json

mortal tendon
#

I tryied to use org.json but i don't understand the docs 🥲 (i rly think i'm stupid)

oblique pollen
mortal tendon
#

the first step, i need to create a src\main repertory ?

oblique pollen
mortal tendon
#

is something to setup projet ?

#

btw it's already installed

oblique pollen
mortal tendon
#

I have this. where did i need past the text ? 🥲

quaint hollow
#

I'd recommend using a proper IDE like IntelliJ CE which has easier onboarding for you, including when you want to use Maven/Gradle.

slate lintelBOT
mortal tendon
#

okok, i install it to try 😭

#

Thanks for the tips 😉

mortal tendon
mortal tendon
#

ok mb i need to stay on java page xD, but i have to get a groupeID

mortal tendon
#

yep i see it, thanks ! 🙂

mortal tendon
#

And i never use something like this

quaint hollow
#

I wouldn't have kept the default groupID but that's a different matter.

radiant relic
mortal tendon
#

i didn't name anything atm 🥲

radiant relic
mortal tendon
#

i juste create a new project with com.fasterxml.jackson.core GroupeID and MonoPOOly in name

quaint hollow
#

And groupID is a used name.

mortal tendon
quaint hollow
mortal tendon
#

i have just this, i see "groupeId" like
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>

#

so i use the groupeId 🥲

radiant relic
mortal tendon
#

ngl i didn't understand why is an error to use it

#

but i think i have an idea.
just, "com" , "edu" , .. is necessary or not ?

gritty creek
#

It's generally part of the package (possibly excluding the project name from it). You don't have to put at tld there, but using a proper domain is best practice. Before I got my own domain I used io.github.<github username> (you get a free website from github at <github username>.github.io)

mortal tendon
#

ohhh, with my university i have a gitlab project, so i will use it. okayyyy

mortal tendon
radiant relic
mortal tendon
#

is an university project where we are 5 in the group, for that i don't want to have problem on it

radiant relic
mortal tendon
#

oki , thanks !

radiant relic
mortal tendon
#

okay