-
Notifications
You must be signed in to change notification settings - Fork 135
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
Unable to deserialize (extended) Schema #67
Comments
Here is the unit test: |
Ok, first things first: the immediate reason for failure is use of type 'object', which will result in basic But adding handling of this new type is more involved. I'll see if I can figure that out, and if so, will add instructions for doing that. |
Sample implementation will be found from 'src/test/java/com/fasterxml/jackson/module/jsonSchema/CustomSchemaReadTest.java'. Here are the things needed: @JsonTypeIdResolver(MyResolver.class)
public static class MySchema extends ObjectSchema { }
static class MyResolver extends JsonSchemaIdResolver
{
@Override
public String idFromValue(Object value) {
if (value instanceof MySchema) {
return "CUSTOM";
}
return super.idFromValue(value);
}
@Override
public String idFromValueAndType(Object value, Class<?> suggestedType) {
if (value instanceof MySchema) {
return "CUSTOM";
}
return super.idFromValueAndType(value, suggestedType);
}
@Override
public JavaType typeFromId(DatabindContext ctxt, String id) {
if ("CUSTOM".equals(id)) {
return ctxt.constructType(MySchema.class);
}
return super.typeFromId(ctxt, id);
}
} so it just boils down to adding handling for custom type; you can choose whatever id you want, and it would be possible to make this bit more general. What I do not know is why handling was done this way: standard Jackson mechanism would have been to instead of basic |
Hi Tatu, Thank you very much for this! Best regards, |
Hi,
It appears that it's not possible to deserialize a schema into an extended
ObjectSchema
class (ie:class MySchema extends ObjectSchema
)Thanks!
Sebastien
The text was updated successfully, but these errors were encountered: