jakartaee / jsonp-api

Jakarta JSON Processing
https://eclipse.org/ee4j/jsonp
Other
138 stars 59 forks source link

Jackson Databind serialization error #399

Closed snturk closed 1 year ago

snturk commented 1 year ago

I am trying to convert an object to JsonValue by applying following on both using jakarta.json and javax.json packages:

objectMapper.convertValue(p, JsonValue.class)

Everything is as expected when using javax.json. However, jakarta.json triggers the exception below:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `jakarta.json.JsonValue` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
 at [Source: UNKNOWN; byte offset: #UNKNOWN]
    at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67) ~[jackson-databind-2.15.0.jar:2.15.0]
    at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1915) ~[jackson-databind-2.15.0.jar:2.15.0]
    at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:414) ~[jackson-databind-2.15.0.jar:2.15.0]
    at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1360) ~[jackson-databind-2.15.0.jar:2.15.0]
    at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:274) ~[jackson-databind-2.15.0.jar:2.15.0]
    at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:4539) ~[jackson-databind-2.15.0.jar:2.15.0]
    at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:4475) ~[jackson-databind-2.15.0.jar:2.15.0]

I don't think that it caused by jackson-databind package. Is this a known issue or there is a difference between two json packages?

lukasj commented 1 year ago

The stacktrace has no evidence of jakarta.json/javax.json being guilty, file an issue against jackson-databind, please.

snturk commented 1 year ago

Yes I am aware of that. But I'm using same version of jackson-databind when trying both jakarta.json/javax.json libraries.

Javax:

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.1.4</version>
</dependency>

Jakarta:

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>jakarta.json</artifactId>
    <version>2.1.1</version>
</dependency>

I know that versions are different but I cannot find a change between versions related to that. I'm talking about an issue in this repository about the problem rather than what is to blame.

lukasj commented 1 year ago

javax version uses javax.json package while jakarta version uses jakarta.json package. The releases page contains the most important changes between each versions.