ralfstx / minimal-json

A fast and small JSON parser and writer for Java
MIT License
732 stars 186 forks source link

JsonObject as object field breaks Jackson object mapping #92

Open nbartels opened 6 years ago

nbartels commented 6 years ago

I have a object that contains a minimal-json JsonObject as field and I try to serialise the object with jackson to JSON to store the object as String and deserialise it afterwards. The mechanism is explained here:

http://www.baeldung.com/jackson-object-mapper-tutorial

As soon as I try to deserialise the stored object I run into this error message:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 
Cannot construct instance of `com.restfb.json.JsonNumber` 
(no Creators, like default construct, exist): cannot deserialize from Object value 
(no delegate- or property-based Creator)

According to this message the default constructor is missing, but adding one seems not be a solution because JsonNumber, JsonString and JsonLiteral contain a inner private final field and it seems this disturbs the deserialisation process.

ATM the solution is to store the JSON as String and have a getter that parses the String with minimal-json on demand, but perhaps you are interested in solving this on your side ;)

bernardosulzbach commented 6 years ago

I have a object that contains a minimal-json JsonObject as field (...)

I understand the issue you are describing. However, I've never considered having a class with a JsonObject member. Does it make sense in your domain? Is it a payload-like field in a message-like object?

Does Jackson make this possible to fix in the calling code? Such as by registering an object capable of transforming JsonObject into something that Jackson can understand and vice-versa.