Skip to content
This repository has been archived by the owner on Nov 27, 2021. It is now read-only.

Fails to Deserialize #6

Open
1fxe opened this issue Aug 7, 2021 · 2 comments
Open

Fails to Deserialize #6

1fxe opened this issue Aug 7, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@1fxe
Copy link

1fxe commented Aug 7, 2021

java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at xyz.matthewtgm.json.serialization.JsonDeserializer.createClassInstance(JsonDeserializer.java:68)
	at xyz.matthewtgm.json.serialization.JsonDeserializer.deserialize(JsonDeserializer.java:31)
	at dev.fxe.TGMJsonBenchmark.deserialize(TGMJsonBenchmark.java:19)
	at dev.fxe.DataGenerator.main(DataGenerator.java:39)
public static void deserialize() throws FileNotFoundException {
	BufferedReader bufferedReader = new BufferedReader(new FileReader("people.json"));
	String data = bufferedReader.lines().collect(Collectors.joining());
	Person[] people = JsonDeserializer.deserialize(data, Person[].class);
}


public class Person {

	String fullName;
	String firstName;
	String lastName;
	String address;
	int age;
	Book favouriteBook;

	public Person(String fullName, String firstName, String lastName, String address, int age, String author, String title) {
		this.fullName = fullName;
		this.firstName = firstName;
		this.lastName = lastName;
		this.address = address;
		this.age = age;
		this.favouriteBook = new Book(author, title);
	}
}

public class Book {

	String author;
	String title;

	public Book(String author, String tittle) {
		this.author = author;
		this.title = tittle;
	}
}

The file to deserialize

people.json

@Deftu Deftu added the bug Something isn't working label Aug 7, 2021
@Deftu Deftu self-assigned this Aug 7, 2021
@Deftu
Copy link
Collaborator

Deftu commented Aug 7, 2021

Use the JsonReader, and your class needs to have an empty constructor for it to work atm.

@Deftu
Copy link
Collaborator

Deftu commented Sep 5, 2021

It appears I forgot to make inner-class serialization and deserialization. I'll make it when possible.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants