Skip to content

Commit

Permalink
fixes after review. BeanDeserializerWithValidation moved.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-zinchenko committed Nov 20, 2024
1 parent 55d6743 commit 12c9773
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.epam.aidial.core.server.validation;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.deser.BeanDeserializer;
import com.fasterxml.jackson.databind.deser.BeanDeserializerBase;
import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;

import java.io.IOException;

import static com.epam.aidial.core.server.validation.ValidationUtil.validate;

public class BeanDeserializerModifierWithValidation extends BeanDeserializerModifier {
@Override
public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
Expand All @@ -15,4 +21,20 @@ public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, Bean
}
return deserializer;
}

private static class BeanDeserializerWithValidation extends BeanDeserializer {

protected BeanDeserializerWithValidation(BeanDeserializerBase src) {
super(src);
}

@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
Object instance = super.deserialize(p, ctxt);
validate(instance);
return instance;
}

}

}

This file was deleted.

0 comments on commit 12c9773

Please sign in to comment.