-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonValue Ignored #208
Comments
These are the options I use:
|
Hi @mbenz89, I've looked into this a bit and came up with a CustomDefinitionProvider, which I considered introducing under a new standard public class CustomJsonValueDefinitionProvider implements CustomDefinitionProviderV2 {
@Override
public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, SchemaGenerationContext context) {
ResolvedTypeWithMembers typeWithMembers = context.getTypeContext().resolveWithMembers(javaType);
List<ResolvedMember<?>> jsonValueMembers = Stream
.concat(Stream.of(typeWithMembers.getMemberFields()), Stream.of(typeWithMembers.getMemberMethods()))
.filter(member -> Optional.ofNullable(member.get(JsonValue.class)).filter(JsonValue::value).isPresent())
.collect(Collectors.toList());
if (jsonValueMembers.size() != 1) {
// no unambiguous @JsonValue target could be detected
return null;
}
ResolvedType underlyingValueType = jsonValueMembers.get(0).getType();
ObjectNode customNode = context.createStandardDefinitionReference(underlyingValueType, javaType.equals(underlyingValueType) ? this : null);
return new CustomDefinition(customNode, CustomDefinition.DefinitionType.INLINE, CustomDefinition.AttributeInclusion.YES);
}
} That would be applied (in code) like this: builder.forTypesInGeneral()
.withCustomDefinitionProvider(new CustomJsonValueDefinitionProvider()) Can a As to your question regarding |
Hi @CarstenWickner. Thanks for the help! Your implementation works just fine for atomic values!
Unfortunately,
I had to change this to
Happy to propose a PR with some test cases as soon as I got it working properly :).
|
Hi!
I have a case like this:
My code looks like this:
I would expect that the
JsonValue
property leads to inlining the value ofAnotherObject
. Also for the case where the type parameterT
isjava.lang.Object
the value type is not printed: `"value": {}".Any help on this? I would implement the type conversion myself but I was only able to change properties in the type
AnotherType
but not entirely replace properties of that type with the generic type of the usedAnotherType
field.It would be awesome if you could provide me with a stub or hint on how to implement a custom Module to replace
"$ref" : "#/$defs/AnotherObject(String)"
with"type": "string"
(for example).The text was updated successfully, but these errors were encountered: