GithubHelp home page GithubHelp logo

unbroken-dome / jackson-bean-validation Goto Github PK

View Code? Open in Web Editor NEW
20.0 3.0 13.0 188 KB

A Jackson module that performs Java Bean Validation during deserialization.

License: MIT License

Kotlin 22.29% Java 77.71%
jackson json validation bean-validation json-validation

jackson-bean-validation's People

Contributors

tedliang avatar tkrullmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jackson-bean-validation's Issues

@JsonTypeInfo Jacson annotation disables validation?

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");
  }
}

Support for jakarta bean validation

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.

Incompatible with BeanBuilderDeserializer

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.