Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving Java objects into files

I have the following class in Java. I would like to be able to save it into a common file format that would be able to moved across different pc's. I know about object serialization but I was wondering what are my other options and what are their respective pros and cons. Thanks! Like for example a serialized file is not human readable and therefore a con.

public class NervousSystem {
    private CentralNervousSystem CNS;
    private PeripheralNervousSystem PNS;

    public NervousSystem(Neocortex neocortex, LateralGeniculateNucleus LGN, Retina retina) {
        this.CNS = new CentralNervousSystem(neocortex, LGN);
        this.PNS = new PeripheralNervousSystem(retina);
    }

    public CentralNervousSystem getCNS() {
        return this.CNS;
    }

    public PeripheralNervousSystem getPNS() {
        return this.PNS;
    }
}
like image 367
Wang-Zhao-Liu Q Avatar asked Nov 30 '22 21:11

Wang-Zhao-Liu Q


1 Answers

You can serialize the objects to JSON using e.g. Jackson, which will greatly improve their human readability

like image 163
Zim-Zam O'Pootertoot Avatar answered Dec 04 '22 22:12

Zim-Zam O'Pootertoot