Open ajr3-gen opened 9 months ago
My recollection may be wrong, but I thought JSON Schema didn't support all Java native types? See f.ex:
https://github.com/saasquatch/json-schema-inferrer/issues/17
and from there:
https://json-schema.org/understanding-json-schema/reference/type
If so, choices are number
(more generic) or int
for integral numeric types.
I don't see a suggestion for separate "long"
type, or modifier. This sort of makes sense given how JSON format itself does not really have anything to denote magnitude of integer (or, floating-point for that matter) types.
I guess I'm trying to do more with the schema than it's designed for. I'd like to generate a JsonSchema from an object and then be able to exactly describe the original object from that schema. But if the JsonSchema spec uses a single type to represent multiple Java types, then it is losing some of the source information so you really can't do the reverse conversion.
Based on a suggestion I found somewhere, annotations offer a potential workaround. If my source object is defined with an annotation like this:
public class Demonstrator {
@JsonPropertyDescription("long")
private Long myLong;
// ... (plus getter and setter) ...
}
then the output includes the description:
Mapped object: {
"type" : "object",
"id" : "urn:jsonschema:org:example:Demonstrator",
"properties" : {
"myLong" : {
"type" : "integer",
"description" : "long"
}
}
}
So while this is not a general solution, it would help in cases where I have control over the original class.
Yes, I understand why it would be useful, just pointing out limitations.
I probably should also mention that this module is deprecated and no longer actively developed -- there are better, maintained alternatives in existence. We still accept PRs for bug fixes and improvements tho if anyone has time to try tackling issues. But there is no active development planned otherwise and module will not be brought along to Jackson 3.0.
This was mentioned in an older issue but I want to bring it up again: the JsonSchema generator does not differentiate between longs and ints. Both types end up as "integer" in the schema. It is said that when data is retrieved, it will be treated as long or int based on its size and that may be so. But when one examines the JsonSchema object, everything is "integer". You can see this from the code shown in the Readme for this package. Here is a very simple demonstration of it; generating a schema from an object with an
int
, along
, and aLong
simply represents them all as "integer".Is there any way to preserve the original type information for the properties?