-1
public class JsonToJava {

    public static void main(String[] args) {
        Gson gson = new Gson();

        try (Reader reader = new FileReader("C:\\Users\\44772\\Documents\\NetBeansProjects\\JsonTest\\staff.json")) {

            // Convert JSON File to Java Object
            Staff staff = gson.fromJson(reader, Staff.class);
            
            
            System.out.println(staff);
           

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}

I've implemented a simple class with getters and setters and created a file using gson.toJson but now im trying to deserialize. The output is the package name and some numbers i'm not too sure what i've done wrong:

'com.mycompany.jsontest.Staff@5fdef03a'

  • 2
    Please refer to this post [How do I print my Java object without getting "SomeType@2f92e0f4"?](https://stackoverflow.com/questions/29140402/how-do-i-print-my-java-object-without-getting-sometype2f92e0f4) – LHCHIN Jan 20 '22 at 00:22

1 Answers1

0

You need to implement #toString method in your Staff class. Either generate it with IDE e.g. https://www.jetbrains.com/help/idea/generating-code.html#generate-tostring or you can use https://projectlombok.org/features/ToString

Mariusz W.
  • 116
  • 3