Auties00 / Cobalt

Standalone unofficial fully-featured Whatsapp Web and Mobile API for Java and Kotlin
MIT License
647 stars 188 forks source link

json serialization/deserialization of keys and stores does not work #242

Closed angleto closed 1 year ago

angleto commented 1 year ago

The deserialization of a previously serialized Keys or Store data structure raise exceptions. The errors are like the following:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.util.concurrent.ConcurrentHashMap<it.auties.whatsapp.model.contact.ContactJid,java.util.concurrent.ConcurrentLinkedDeque<it.auties.whatsapp.model.info.MessageInfo>>` from Array value (token `JsonToken.START_ARRAY`)

To reproduce the issue just serialize complete Keys and Store classes through the toJson function and deserialize them back using the ObjectMapper class.

Auties00 commented 1 year ago

The deserialization of a previously serialized Keys or Store data structure raise exceptions. The errors are like the following:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.util.concurrent.ConcurrentHashMap<it.auties.whatsapp.model.contact.ContactJid,java.util.concurrent.ConcurrentLinkedDeque<it.auties.whatsapp.model.info.MessageInfo>>` from Array value (token `JsonToken.START_ARRAY`)

To reproduce the issue just serialize complete Keys and Store classes through the toJson function and deserialize them back using the ObjectMapper class.

What version are you using?

angleto commented 1 year ago

What version are you using?

I can reproduce the issue with the data structures from the master version.

Auties00 commented 1 year ago

What version are you using?

I can reproduce the issue with the data structures from the master version.

Delete that session and create a new one. You probably changed version without doing it which is not something you can do

angleto commented 1 year ago

What version are you using?

I can reproduce the issue with the data structures from the master version.

No, that's not the case. I deleted the keys and store and recreated them, but the problem persists especially after connecting and downloading the data (contacts, conversations) from WhatsApp. Is there any unit test that verify full serialization of stores and keys? May the they would reproduce the issue. Thanks

angleto commented 1 year ago

I was able to make it working using your JSON utility class: I didn't notice it before, I used toJson to serialize and an Object mapper for deserialization. Though it was necessary to enable the following properties building the ObjectMapper on the Json class:

                    .enable(WRITE_ENUMS_USING_INDEX)
                    .enable(READ_ENUMS_USING_TO_STRING)

I updated a few dependencies as well, If you find the changes useful they are in the PR #224 already opened.