unbroken-dome / jackson-bean-validation Goto Github PK
View Code? Open in Web Editor NEWA Jackson module that performs Java Bean Validation during deserialization.
License: MIT License
A Jackson module that performs Java Bean Validation during deserialization.
License: MIT License
https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/
Given this announcement it looks like we're no longer going to be able to access the library via jcenter.
If deserialization is performed using @JsonCreator
than ConstraintViolationException
is not thrown at all.
Test case: https://gist.github.com/t3hk0d3/f0abb5ae09ae48dee36030fbb5e9f294
Excellent library! I was hoping to use it to validate polymorphic JSONs implemented using Jackson's @JsonTypeInfo
annotation. Unfortunately, the use of this annotation appears to turn off the validation on the polymorphic object.
I include a quick reproduction test below. If you remove the @JsonTypeInfo
annotation, validation will be performed as expected.
Is there any workaround I could use to make jackson-bean-validation work with @JsonTypeInfo
?
public class ValidatorTest {
@JsonValidated
public static class Impl implements Interface {
@JsonProperty @NotEmpty public String s;
}
@JsonValidated
@JsonTypeInfo(use = Id.NAME, property = "type")
@JsonSubTypes({@JsonSubTypes.Type(name = "default", value = Impl.class)})
public interface Interface {}
@Test
public void validation() throws JsonProcessingException {
final ObjectMapper om = new ObjectMapper();
final ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
final BeanValidationModule module = new BeanValidationModule(factory);
om.registerModule(module);
final Interface invalid = new Impl();
final String invalidJson = om.writeValueAsString(invalid);
try {
om.readValue(invalidJson, Impl.class);
} catch (ConstraintViolationException e) {
return;
}
Assertions.fail("Expecting ConstraintViolationException");
}
}
Is there any plan to move from javax.validation to jakarta.validation?
Since all the newer versions of validation implementations are using the new jakarta.validation API this would be required to make it still useable, for example in Spring-boot 3.0.
Just copying the previous deserializer from the BeanDeserializerModifier
breaks building with BuilderBasedDeserializer
, since it no longer gets a chance to call finishBuild
in its own deserialize. I'm not sure what the correct fix is, but somehow the previous deserializer's deserialize
still needs to be called.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.