I try to migrate from vertx 4.x to 5.0.2. In my project originally was creating a RouterFactory to create a Router using OpenAPI3RouterFactory.rxCreate using a spec.yaml file of OpenAPI v3.0.0. Now, I changed it to routerBuilder using OpenAPICtract.rxFrom using the same spec.yaml, mapping it later using RouterBuilder.create() to create RouterBuilder. The issue happens on OpenAPICtract.rxFrom() logging:
class java.lang.Long cannot be cast to class java.lang.Integer (java.lang.Long and java.lang.Integer are in module java.base of loader 'bootstrap') at io.vertx.json.schema.impl.SchemaValidatorImpl.validate(SchemaValidatorImpl.java:446) SchemaValidatorImpl.java:446 at io.vertx.json.schema.impl.SchemaValidatorImpl.validate(SchemaValidatorImpl.java:204)
This refers to the following code line:
if (schema.containsKey("minProperties") && keys.size() < schema.<Integer>get("minProperties"))
more specifically schema.<Integer>get("minProperties") returns Long with value 1 and the cast fails. Initially thought that was a parcing error on the spec.yaml file so I created io.vertx.core.json.JsonObject from this YAML and later used OpenAPIContract.rxFrom(Vertx, JsonObject). I verified that JsonObject is created successfully and represents correctly the spec.yaml, but the error is the same.
All vertx artifacts that are used in my project are 5.0.2.
Seems that schema instance is vertx internal, so I am not sure how can I proceed to fix it.
1 Answer 1
Seems that Vert.x is delegating all JSON parsing to Jackson (com.fasterxml.jackson.databind.ObjectMapper under the hood).
Using the following before creating OpenAPIContract seems to fix the issue:
import com.fasterxml.jackson.databind.DeserializationFeature;import io.vertx.core.json.jackson.DatabindCodec;
// Disable using Long for integers so small numbers become IntegerDatabindCodec.mapper().configure(DeserializationFeature.USE_LONG_FOR_INTS, false);