Pretius / pretius-jddl

Java library for JSON deserialization with runtime configured, modifiable and dynamic deserialization rules, utilizing Jackson for low-level operations.
https://pretius.com/technologies/json-dynamic-deserialization-library/
Apache License 2.0
5 stars 0 forks source link

Any? as a type of a field of a class for deserialization #3

Open vetalalien opened 3 months ago

vetalalien commented 3 months ago

Hi, there!

I attempted to use in Kotlin the jddl deserializer with these json and class for deserialization:

The json is:

{
   "dummy": 123
}

The class is:

class DeserializedItemObject {
    val dummy: Any? = null
}

The line related to deserialing start is here: val obj: DeserializedItemObject = deserializer.deserialize(json, DeserializedItemObject::class.java)

This way I suppose, that dummy can be whatever json simple types - integer, string, boolean etc.

But I got the next error after running the code: "Caused by: com.pretius.jddl.JddlCanNotDeseializeNumberException: Unsupported expected class=[class java.lang.Object] for number deserializer".

Help me, please, to figure out what's wrong. Maybe I should use some specific rule provided by the library, or, perhaps, I'm misusing the library somehow?

Thanks much in advance!

VaverDariush commented 3 months ago

Hi!

The whole idea of the lib was to deserialize to as specific type as possible. The lib treats numbers as primitive and primitives are not objects in java, hence they can not be cast to an Object reference.

On Wed, 7 Aug 2024, 19:08 vetalalien, @.***> wrote:

Hi, there!

I attempted to use in Kotlin the jddl deserializer with these json and class for deserialization:

The json is:

{ "dummy": 123 }

The class is:

class DeserializedItemObject { val dummy: Any? = null }

The line related to deserialing start is here: val obj: DeserializedItemObject = deserializer.deserialize(json, DeserializedItemObject::class.java)

This way I suppose, that dummy can be whatever type - integer, string, boolean, ..., some another user specific type

But I got the next error after running the code: "Caused by: com.pretius.jddl.JddlCanNotDeseializeNumberException: Unsupported expected class=[class java.lang.Object] for number deserializer".

Help me, please, to figure out what's wrong (maybe I'm misusing the library somehow...). Thanks much in advance!

— Reply to this email directly, view it on GitHub https://github.com/Pretius/pretius-jddl/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEW3H3NXIWIXSB3FF65SE3ZQJH7TAVCNFSM6AAAAABME2KZV6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGQ2TGOJUG44TGNA . You are receiving this because you are subscribed to this thread.Message ID: @.***>